import pandas as pd
# 创建示例数据
data = pd.DataFrame({'时间戳': ['2022-01-01 12:01:00', '2022-01-01 12:35:00', '2022-01-01 13:17:00', '2022-01-01 14:43:00', '2022-01-01 15:12:00'], '值': [1, 2, 3, 4, 5]})
# 将时间戳转换为日期时间格式
data['时间戳'] = pd.to_datetime(data['时间戳'])
# 按小时分组
data_grouped = data.groupby(data['时间戳'].dt.hour)
# 计算每组的计数
result = data_grouped.size()
print(result)
上一篇:按小时分组获取计数
下一篇:按小时分组计算列的总和