Pandas Changing the format of NaN values when saving to CSV

后端 未结 4 2340
南笙
南笙 2021-02-19 06:55

I am working with a df and using numpy to transform data - including setting blanks (or \'\') to NaN. But when I write the df to csv - the output contains the string \'nan\' as

4条回答
  •  余生分开走
    2021-02-19 07:47

    Pandas to the rescue, use na_rep to fix your own representation for NaNs.

    df.to_csv('file.csv', na_rep='NULL')
    

    file.csv

    ,index,x,y,z
    0,0,1.0,NULL,2
    1,1,NULL,3.0,4
    

提交回复
热议问题