When using a group using the as_index function, it can be set to true or false depending on whether you want the column with which you were grouped to be the output index.
import pandas as pd table_r = pd.DataFrame({ 'colors': ['orange', 'red', 'orange', 'red'], 'price': [1000, 2000, 3000, 4000], 'quantity': [500, 3000, 3000, 4000], }) new_group = table_r.groupby('colors',as_index=True).count().sort('price', ascending=False) print new_group
exit:
price quantity colors orange 2 2 red 2 2
Now with as_index = False
colors price quantity 0 orange 2 2 1 red 2 2
Note that colors are no longer an index when changing as_index = False
Marc vT
source share