我有3个位置的每小时降雨量数据框。头部和尾部提供如下数据的详细信息。为了理解降水的日变化,我想收集所有日子和所有年份的所有小时数据。
hourly_series.head()
loc1_data loc2_data loc3_data
2013-10-01 05:30:00+00:00 0.5 1 1
2013-10-01 06:30:00+00:00 NaN NaN NaN
2013-10-01 07:30:00+00:00 NaN NaN NaN
2013-10-01 08:30:00+00:00 0 0 0
2013-10-01 09:30:00+00:00 NaN NaN NaN
[5 rows x 3 columns]
hourly_series.tail()
loc1_data loc2_data loc3_data
2014-01-01 00:30:00+00:00 7.5 1 5
2014-01-01 01:30:00+00:00 0 0 0
2014-01-01 02:30:00+00:00 0 2 0
2014-01-01 03:30:00+00:00 0 4.5 0
2014-01-01 04:30:00+00:00 1 0 0
我试过
hourly_grouped = hourly_series.groupby([(lambda x:x.year,lambda x:x.month, lambda x: x.time)])
但是,我无法实现所需的输出。我是熊猫包的新手。
答案 0 :(得分:2)
hourly_series['hour'] = hourly_series.index
hourly_series['hour'] = hourly_series['hour'].apply(lambda x: x.hour)
hourly_series.groupby(['hour']).var() # Or any other stats function