Remove dtype datetime NaT

前端 未结 4 1958
面向向阳花
面向向阳花 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:44

    @unutbu's answer will work fine, but if you don't want to modify the DataFrame, you could do something like this. to_html takes a parameter for how NaN is represented, to handle the NaT you need to pass a custom formatting function.

    date_format = lambda d : pd.to_datetime(d).strftime('%Y-%m-%d') if not pd.isnull(d) else ''
    
    df1.to_html(na_rep='', formatters={'date': date_format})
    

提交回复
热议问题