【发布时间】:2021-10-28 08:17:42
【问题描述】:
我有一个 DatetimeIndex 索引系列 s1 之类的
s1
time
2021-08-24 09:24:16+09:00 11933142
2021-08-24 10:00:03+09:00 11785209
2021-08-24 11:00:03+09:00 14462866
2021-08-24 19:00:04+09:00 11419204
2021-08-24 20:00:03+09:00 11757634
Name: x, dtype: int64
一周中的每一天都需要mean()。然后我想获取索引的day_name() 来绘制图形标签,但我不能,因为DatetimeIndex 现在变成了int。
g1 = s1.groupby(s1.index.dayofweek).mean()
----> 3 g1.index.day_name()
AttributeError: 'Int64Index' object has no attribute 'day_name'
最聪明的解决方法是什么?
【问题讨论】:
-
按日期分组?
-
我忘了提一件事。我想保持
dayofweek的排序顺序