我在pandas中非常新手,想要使用groupby
。我有一个包含多列的数据框。
- 我想要按照特定的一列进行分组,然后根据另一列对每个分组进行排序。
- 我想要按照
col1
进行分组,然后按照col5
对每个分组进行排序,然后使用reset_index
来获取所有行。 - 我得到了以下错误信息:
AttributeError: Cannot access callable attribute 'reset_index' of 'DataFrameGroupBy' objects, try using the 'apply' method
。
我的输入数据框:
col1 | col2 | col3 | col4 | col5
=================================
A | A1 | A2 | A3 | DATE1
A | B1 | B2 | B3 | DATE2
我的代码:
df.sort_values(['col5'],ascending=False).groupby('col1').reset_index()
groupby
代码是什么? - jezrael