I have been struggling with this question for a long while, and I tried different methods.
I have a simple DataFrame as shown,
I can use code to rep
Make the dtype object
dtype
object
dfTest2 = pd.DataFrame(dict(InvoiceDate=pd.to_datetime(['2017-06-01', pd.NaT]))) dfTest2.InvoiceDate.astype(object).where(dfTest2.InvoiceDate.notnull(), None) 0 2017-06-01 00:00:00 1 None Name: InvoiceDate, dtype: object