【问题标题】:I keep getting a date format error when trying to convert an int into a date尝试将 int 转换为日期时,我不断收到日期格式错误
【发布时间】:2022-08-09 02:18:02
【问题描述】:

所以我目前有一个数据集,其日期列为 int,例如 10280910/28/2009。所以我试图将此列转换为具有正确日期格式的实际日期列。

我从另一个关于堆栈溢出的问题中尝试了这段代码:

curry[\'Datetime\'] = curry[\'Date\'].apply(lambda x: pd.to_datetime(str(x), format=\'%m/%d/%Y\'))

但是这一行返回这个错误:time data \'102809\' does not match format \'%m/%d/%Y\' (match)

    标签: python pandas


    【解决方案1】:

    将其更改为:

    curry['Datetime'] = curry['Date'].apply(lambda x: pd.to_datetime(str(x), format='%m%d%Y'))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-12
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 2023-03-30
      • 2011-08-13
      相关资源
      最近更新 更多