【发布时间】:2022-01-22 20:33:47
【问题描述】:
我有以下具有几年每小时数据的时间序列:
local time ghi mean
0 2013-01-01 00:00:00 0.0
1 2013-01-01 01:00:00 0.0
2 2013-01-01 02:00:00 -9999
3 2013-01-01 03:00:00 0.0
4 2013-01-01 04:00:00 0.0
.. ... ...
8754 2016-12-31 18:00:00 427.5
8755 2016-12-31 19:00:00 194.9
8756 2016-12-31 20:00:00 -9999
8757 2016-12-31 21:00:00 237.6
8758 2016-12-31 22:00:00 -9999
8759 2016-12-31 23:00:00 0.0
我需要计算值 -9999 出现的次数并按年和月分组。所需的输出类似于:
local time ghi mean
0 2013-01 1
.. ... ...
8 2016-12 2
我试过了:
df.groupby(df["local time"].dt.strftime('%Y-%m')).df['ghi mean'].value_counts()[-9999]
但是得到了:
AttributeError: 'Series' object has no attribute 'df'
【问题讨论】:
-
我想你只是想要
df.groupby(df["local time"].dt.strftime('%Y-%m'))['ghi mean'].value_counts()[-9999]列选择只是 groupby 的方括号。
标签: python pandas dataframe datetime