renardo
renardo

Reputation: 87

NaNs disappear after saving to excel file

Missing files in my data was represented at 999, 99, 9999, so i used df.replace() to change them to NaNs however, NaNs disappear after saving to excel.

df4 = df3.replace('99', np.nan)

df4.to_excel('42003hnew.xlsx', sheet_name = 'Sheet1')

Upvotes: 1

Views: 191

Answers (1)

root
root

Reputation: 33793

By default, NaN is represented by an empty string when output is written. Use the na_rep parameter of to_excel to change this:

df4.to_excel('42003hnew.xlsx', sheet_name='Sheet1', na_rep='N/A')

Upvotes: 2

Related Questions