Python pandas :将datetime列组合成小时和分钟聚合 [英] Python Pandas: Group datetime column into hour and minute aggregations

查看:320
本文介绍了Python pandas :将datetime列组合成小时和分钟聚合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是相当简单的,但经过将近一整天,我还没有找到解决方案。我已经用read_csv加载了我的数据框,并且轻松解析,组合并将日期和时间列编入一列,但现在我想能够根据与您可以做的相似的时间和分钟分组进行重塑和执行计算优势枢纽

This seems like it would be fairly straight forward but after nearly an entire day I have not found the solution. I've loaded my dataframe with read_csv and easily parsed, combined and indexed a date and a time column into one column but now I want to be able to just reshape and perform calculations based on hour and minute groupings similar to what you can do in excel pivot.

我知道如何重新采样到小时或分钟,但它保持与每个小时/分钟相关联的日期部分,而我想将数据集合只有时间和分钟相似分组在excel枢轴,并选择小时和分钟,但不选择任何其他。

I know how to resample to hour or minute but it maintains the date portion associated with each hour/minute whereas I want to aggregate the data set ONLY to hour and minute similar to grouping in excel pivots and selecting "hour" and "minute" but not selecting anything else.

任何帮助将不胜感激。

Any help would be greatly appreciated.

推荐答案

你不能这样做, df 是你的DataFrame:

Can't you do, where df is your DataFrame:

times = pd.to_datetime(df.timestamp_col)
df.groupby([times.hour, times.minute]).value_col.sum()

这篇关于Python pandas :将datetime列组合成小时和分钟聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆