使用Python将相同的DateTime值求和相同的DateTime值

发布于 2025-02-04 03:44:30 字数 375 浏览 3 评论 0原文

我有一个带有DateTime列的DataFrame,我试图以相同的DateTime以所有值的总和来获得打印,然后在所有值之后进行平均值。 这是我所拥有的:

df[col] = pd.to_datetime(df[col]).dt.date
df.groupby([col]).sum()

但是我只是从所有日期打印出来,而不是它们与它们相关的值

Date_Recieved
2017-01-01
2017-01-02
2017-01-03
2017-01-04
2017-01-05

之后出现的频率,我希望保存所有值并进行单个平均值

I have a dataframe with a datetime column, I am trying to get the print out of the sum of all the values with the same datetime and then do an average afterwards of all the values.
Here is what I have:

df[col] = pd.to_datetime(df[col]).dt.date
df.groupby([col]).sum()

But I just get a print out of all the dates and not their associated values with how often they appear

Date_Recieved
2017-01-01
2017-01-02
2017-01-03
2017-01-04
2017-01-05

After this I was hoping to save all the values and do a single average

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文