日期在Python之间的平均差异 [英] Average difference between dates in Python

查看:150
本文介绍了日期在Python之间的平均差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列datetime对象,并希望计算它们之间的平均增量。

I have a series of datetime objects and would like to calculate the average delta between them.

例如,如果输入的是(2008-10-01 12点15分零零秒,2008-10-01 12:25:00,2008-10-01 12:35:00) ,那么平均增量会完全00:10:00,或10分钟。

For example, if the input was (2008-10-01 12:15:00, 2008-10-01 12:25:00, 2008-10-01 12:35:00), then the average delta would be exactly 00:10:00, or 10 minutes.

如何计算这个使用Python有什么建议?

Any suggestions on how to calculate this using Python?

推荐答案

您可以减去前一个每个连续的日期(导致其重新$ P $一个timedelta对象psents天,秒之差)。然后,您可以平均的timedelta对象找到答案。

You can subtract each successive date from the one prior (resulting in a timedelta object which represents the difference in days, seconds). You can then average the timedelta objects to find your answer.

这篇关于日期在Python之间的平均差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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