【问题标题】:Converting numeric SAS dates to datetimes Pandas将数字 SAS 日期转换为日期时间 Pandas
【发布时间】:2018-01-29 21:12:47
【问题描述】:

我目前正在尝试重现此:convert numeric sas date to datetime in Pandas ,但得到以下错误:

“Python int 太大,无法转换为 C long”

这里和我的日期示例:

    0    1.416096e+09
    1    1.427069e+09
    2    1.433635e+09
    3    1.428624e+09
    4    1.433117e+09
Name: dates, dtype: float64

有什么想法吗?

【问题讨论】:

    标签: python pandas datetime


    【解决方案1】:

    这里有一个小技巧。如果日期列称为“日期”,请尝试

    df['date'] = pd.to_datetime(df['date'] - 315619200, unit = 's')
    

    这里的 315619200 是 1960 年 1 月 1 日到 1970 年 1 月 1 日之间的秒数。

    你得到

    0   2004-11-15 00:00:00
    1   2005-03-22 00:03:20
    2   2005-06-05 23:56:40
    3   2005-04-09 00:00:00
    4   2005-05-31 00:03:20
    

    【讨论】:

      猜你喜欢
      • 2016-07-24
      • 1970-01-01
      • 1970-01-01
      • 2015-01-11
      • 2016-07-29
      • 2023-03-17
      • 2016-08-30
      • 2022-12-21
      相关资源
      最近更新 更多