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 ?