【问题标题】:Convert float time to datetime or timestamp in Python在 Python 中将浮点时间转换为日期时间或时间戳
【发布时间】:2020-08-03 09:00:40
【问题描述】:

我有以下数据框:

Time 列是一个字符串,我想将其转换为时间戳或日期时间格式。但是,当我运行df['Time'] = pd.to_datetime(df['Time']) 时,我总是得到一个错误

OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1-01-01 08:53:30

【问题讨论】:

    标签: python-3.x pandas datetime timestamp python-datetime


    【解决方案1】:

    你确定你得到了正确的列和值。因为跑步

    time = pd.to_datetime("13:30:35.805")
    

    Timestamp('2020-04-20 13:30:35.805000')
    

    如预期的那样输出。 如果你不能直接用 pandas 解决问题,你总是可以手动将字符串拆分为小时、分钟和秒

    h, m, s = map(float, x.split(':'))
    

    并使用这些值创建时间戳

    【讨论】:

      猜你喜欢
      • 2019-02-17
      • 2019-02-03
      • 1970-01-01
      • 1970-01-01
      • 2020-06-15
      • 1970-01-01
      • 1970-01-01
      • 2017-04-25
      • 2022-01-08
      相关资源
      最近更新 更多