NaNs in pandas.DataFrame does not print in Excel

I have a pandas.DataFrame that contains numpy.nan floats. However, when using an Excel script, the fields in which floating numpy.nan should be are empty. I would expect at least a string representation instead of nothing.

Any thoughts on why this might be?

The writer code is as follows:

 writer=pandas.ExcelWriter('output.xls') frame.to_excel(writer,'tab name') writer.save() 

Where the frame looks something like this (pay attention to NaN on 2013-01-1):

  Series ID Risk Bucket Contract PX Last Contract Value (Local) Currency X Contract Value (USD) Currency 2013-01-01 Future_ES EQ ES1 Index NaN NaN 1 NaN USD Curncy 2013-01-02 Future_ES EQ ES1 Index 1447.16 72362.5 1 72362.5 USD Curncy 2013-01-03 Future_ES EQ ES1 Index 1443.68 72187.5 1 72187.5 USD Curncy 2013-01-04 Future_ES EQ ES1 Index 1447.90 72400.0 1 72400.0 USD Curncy 

But the Excel file has spaces (see attached image).

enter image description here

+4
source share
1 answer

From the documentation , you should set the na_rep option to to_excel to your liking. For instance:.

 frame.to_excel(writer,'tab name', na_rep='NA') 
+4
source

Source: https://habr.com/ru/post/1491188/


All Articles