【问题标题】:Python Dataframe: Date Columns Reformatting "NaTType does not support strftime" ErrorPython Dataframe:日期列重新格式化“NaTType 不支持 strftime”错误
【发布时间】:2018-05-26 17:16:09
【问题描述】:

我正在尝试重新格式化以下列名称。它们都已转换为日期时间列。

该代码适用于我列表中的前 3 列。但是,最后两列打破了它。

date_columns = ['DTI', 'DTO', 'DTD', 'DTE', 'DTINS']

for i in date_columns:
    df_EVENT5_13[i] = df_EVENT5_13[i].apply(lambda x:x.date().strftime('%m/%d/%Y'))

以下是我得到的错误:

ValueError: NaTType does not support strftime

【问题讨论】:

    标签: python date strftime reformat


    【解决方案1】:

    试试 df_EVENT5_13[i] = df_EVENT5_13[i].dt.date

    【讨论】:

      猜你喜欢
      • 2014-06-18
      • 2013-07-01
      • 2018-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      • 2018-07-28
      • 1970-01-01
      相关资源
      最近更新 更多