as_index is only applied to aggregators · Issue #4648 · pandas-dev/pandas (original) (raw)

In [7]: df = pd.DataFrame({'item_id': ['b', 'b', 'a', 'c', 'a', 'b'], 'user_id': [1,2,1,1,3,1], 'time': ra
nge(6)})

In [8]: df.groupby('user_id', as_index=False).sum()
Out[8]:
   user_id  time
0        1    10
1        2     1
2        3     4

In [9]: df.groupby('user_id', as_index=False).head()
Out[9]:
          item_id  time  user_id
user_id
1       0       b     0        1
        2       a     2        1
        3       c     3        1
        5       b     5        1
2       1       b     1        2
3       4       a     4        3