我想按工作日的'时间'栏和'id'栏分组。这是我尝试的方式,它会引发错误:
AttributeError: 'Int64Index' object has no attribute 'weekday'.
以下是代码:
grouped_weekday_id = df_sample.set_index('time', drop=False, inplace=False)
grouped_weekday_id = grouped_weekday_id.groupby([df_sample.index.weekday, 'id']).mean().reset_index()
样本数据如下:
time id 64-digits watts temp
0 6/26/2017 0:25 1345 9.0072E+15 3.12 71.52
1 6/26/2017 0:25 144 0 1.2 72.96
...
2 6/26/2017 0:25 1152
3 6/26/2017 0:25 1157
4 6/26/2017 0:25 617
5 6/26/2017 0:25 1328
6 6/26/2017 0:25 913
7 6/26/2017 0:25 1717
以下是df_sample dataframe的数据类型。
time datetime64[ns]
id int64
64-digits int64
watts float64
temp float64