Pandas Changing the format of NaN values when saving to CSV

后端 未结 4 2330
南笙
南笙 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:32

    Using df.replace may help -

    df = df.replace(np.nan, '', regex=True)
    df.to_csv("df.csv", index=False)
    

    (This sets all the null values to '' i.e empty string.)

提交回复
热议问题