Remove dtype datetime NaT

前端 未结 4 1963
面向向阳花
面向向阳花 2020-12-28 16:53

I am preparing a pandas df for output, and would like to remove the NaN and NaT in the table, and leave those table locations blank. An example would be

myd         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-28 17:49

    If all you want to do is convert to a string:

    In [37]: df1.to_csv(None,sep=' ')
    Out[37]: ' col1 col2 date\n0 a b "2014-08-14 00:00:00"\n1 c  \n'
    

    To replace missing values with a string

    In [36]: df1.to_csv(None,sep=' ',na_rep='missing_value')
    Out[36]: ' col1 col2 date\n0 a b "2014-08-14 00:00:00"\n1 c missing_value missing_value\n'
    

提交回复
热议问题