I am very new to pandas and trying to use groupby
. I have a df with multiple columns.
- I want to groupby a particular column and then sort each group based on a different column.
- I want to groupby
col1
and then sort each group bycol5
and then doreset_index
to get all rows of the dataframe. - I get the following error
AttributeError: Cannot access callable attribute 'reset_index' of 'DataFrameGroupBy' objects, try using the 'apply' method
.
My input dataframe:
col1 | col2 | col3 | col4 | col5
=================================
A | A1 | A2 | A3 | DATE1
A | B1 | B2 | B3 | DATE2
My code:
df.sort_values(['col5'],ascending=False).groupby('col1').reset_index()