【发布时间】:2019-01-12 00:45:27
【问题描述】:
我在熊猫中有以下数据框
code date time tank
123 01-01-2018 08:00:00 1
123 01-01-2018 11:00:00 1
123 01-01-2018 12:00:00 1
123 01-01-2018 13:00:00 1
123 01-01-2018 07:00:00 1
123 01-01-2018 09:00:00 1
124 01-01-2018 08:00:00 2
124 01-01-2018 11:00:00 2
124 01-01-2018 12:00:00 2
124 01-01-2018 13:00:00 2
124 01-01-2018 07:00:00 2
124 01-01-2018 09:00:00 2
我按“时间”分组和排序
df= df.groupby(['code', 'date', 'tank']).apply(lambda x: x.sort_values(['time'], ascending=True)).reset_index()
当我执行 reset_index() 时,出现以下错误
ValueError: cannot insert tank, already exists
【问题讨论】:
标签: python pandas dataframe group-by pandas-groupby