Pandas replaces NAN with an arbitrary number when to_latex

I have a large multi-indexed multi-column df data frame that I don't show here. I generate an index fragment as follows:

 subDf = df.sort_index(level=0).loc[:'e'] 

Then this slice contains NaN at the second level of the index:

 >>> subDf.iloc[0:1] change robustness value baseline NaN -14.5 

The csv generated by to_csv() looks right:

 >>> subDf.iloc[0:1].to_csv() Out[15]: 'robustness,value,change\nbaseline,,-14.5\n' 

Similarly, to_html() works like expeted. However, when I try to get latex_output, NaN disappears and 50.00 appears:

 >>> subDf.iloc[0:1].to_latex() Out[14]: u'\\begin{tabular}{llr}\n\\toprule\n & & change \\\\\nrobustness & value & \\\\\n\\midrule\nbaseline & 50.00 & -14.5 \\\\\n\\bottomrule\n\\end{tabular}\n' 

50.00 not a completely arbitrary number, this is the last value in the second layer of the multi-index in the original data frame:

 >>> df.index Out[18]: MultiIndex(levels=[[u'a', u'b', u'c', u'd', u'e', u'baseline', u'f'], [0.01, 0.04, 0.25, 0.75, 0.86, 0.99, 1.0, 2.0, 4.0, 10.0, 50.0]], labels=[[5, 6, 6, 2, 2, 1, 3, 3, 3, 4, 4, 0, 0], [-1, 0, 1, 2, 3, 9, 6, 7, 8, 4, 5, 9, 10]], names=[u'robustness', u'value']) 

Two questions arise:

  • Why is this happening in the first place?
  • If this is really unexpected behavior that I cannot influence in the short term, how can I get around this and get to_latex() print a NaN ?
+7
python pandas nan
source share

No one has answered this question yet.

See related questions:

1782
How can I get the number of items in a list?
1419
Select rows from a DataFrame based on values ​​in a column in pandas
1033
Remove column from panda DataFrame
889
Select multiple columns in pandas data frame
879
Get a list of pandas DataFrame column headers
873
Big data workflows using pandas
637
How to remove Pandas DataFrame rows whose value in a particular column is NaN
381
How to check if any NaN value in Pandas DataFrame
366
How do you check if the number is NaN in JavaScript?
167
Pandas Replace NaN with an empty / empty string

All Articles