【问题标题】:Python3 - Pandas Calculate time difference between stored date and current datePython3 - Pandas 计算存储日期和当前日期之间的时间差
【发布时间】:2019-01-24 09:21:52
【问题描述】:

我有以下代码:

import pandas as pd

current_date = pd.Timestamp.now() #2018-08-17 16:05:53.842894
created_date = pd.to_datetime("2018-07-23 09:52:06.090000")
diffrence = (pd.Timedelta(current_date - feed_created_date).seconds)
print(diffrence)
#output is - 22427

理想的输出应该是 2,182,487。我无法找出为什么这会给出不正确的输出,或者我做错了什么。

任何帮助将不胜感激。 提前致谢。

【问题讨论】:

标签: python-3.x pandas


【解决方案1】:

问题在于seconds 是一个值在>= 0 and less than 1 day 之间的属性。请改用total_seconds()

diffrence = (pd.Timedelta(current_date - created_date).total_seconds())

【讨论】:

    猜你喜欢
    • 2016-06-22
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 1970-01-01
    相关资源
    最近更新 更多