首页 > 解决方案 > 使用python的每个小时的月平均值

问题描述

我有如下数据

   Date_Time           A
2019-09-01 00:00:00  140.857143

2019-09-01 01:00:00  132.8750000

 ...        ...  ...       ...       ...

2019-09-30 22:00:00  120.419355 

2019-09-30 23:00:00  110.285714 

我想平均每个月 9 月(第 9 个月)的每个小时,如下所示使用 python

Date_Time  A
00:00:00 value

01:00:00 value

..............

23:00:00 value

所以基本上是每个小时的月平均值。如何做到这一点请提出任何建议。

标签: python-3.xpandasdataframepandas-groupby

解决方案


我们试试看:

# remove `.dt.floor('H')` if your data is already hourly
hours = df['Date_Time'].dt.floor('H').dt.strftime('%H:%M:%S')
df.groupby(hours)['A'].mean()

推荐阅读