Pandas DataFrame Replace NaT with None

前端 未结 4 1026
南笙
南笙 2020-12-14 08:55

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

4条回答
  •  悲&欢浪女
    2020-12-14 09:25

    Similar approach as suggested by @neerajYadav but without the apply:

    dfTest2['InvoiceDate'] = (dfTest2['InvoiceDate']
                              .astype(str) # <- cast to string to simplify
                                           #    .replace() in newer versions
                              .replace({'NaT': None} # <- replace with None
                             )
    

提交回复
热议问题