简体   繁体   中英

Python Pandas to_datetime returns to NaT

First thanx for reading.

I have a database that comes from sql to excel and like this. 在此处输入图像描述

and the dtypes; 在此处输入图像描述

before turning date columns to time, im trying to get rid of None(s) by;

df.fillna("",inplace=True)

then

df1[["ACT_START_DATE","ACT_END_DATE"]]=df1[["ACT_START_DATE","ACT_END_DATE"]].apply(pd.to_datetime, format="%Y-%m-%d %H:%M:%S")

but empty values turn to NaT

在此处输入图像描述

How can i get rid of those NaT(s)? Aim is empty cell

It's not possible to have a datetime64 column with the string placeholders. It must be an object column. In turn, this will not allow you to use time series/datetime features of pandas. I recommend ignoring NaT during the processing stage and using the fillna({<date_column_name>: ""}) method just before exporting the dataframe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM