【发布时间】:2019-07-23 04:14:42
【问题描述】:
我写了以下代码:
date_format = lambda x: datetime.strptime(x, "%d-%b-%Y") if x!=0 else np.nan
input_file['Business date'] = input_file['Business date'].fillna(0).apply(date_format)
input_file['Date of the Flow'] = input_file['Date of the Flow'].fillna(0).apply(date_format)
当我采用唯一的“营业日期”列时,它显示输出为:
input_file["Business date"].unique()
Out[61]: array(['2019-02-15T00:00:00.000000000', '2019-02-18T00:00:00.000000000'], dtype='datetime64[ns]')
对于“流程日期”:
input_file["Date of the Flow"].unique()
Out[64]:
array([nan, datetime.datetime(2019, 9, 18, 0, 0),
datetime.datetime(2023, 3, 24, 0, 0), ...,
datetime.datetime(2028, 7, 15, 0, 0),
datetime.datetime(2122, 12, 19, 0, 0),
datetime.datetime(2026, 11, 28, 0, 0)], dtype=object)
为什么会这样?另请注意,“流程日期”列的日期为 2505 年。如果我删除这些日期,它会给出与“业务日期”相同的输出,即 dtype='datetime64[ns]'
【问题讨论】:
-
您好,您能否在应用
date_format函数之前向我们提供一些您的原始输入数据示例,即来自input_file["Business date"]和input_file['Date of the Flow']的项目?
标签: python python-3.x datetime spyder