python - to_latex() produces incorrect result with MultiIndex DataFrame -


i suspect bug 0.16.1, can confirm i'm not being idiot?

the df.to_latex() method prints data shifted down 1 row respect multiindex (but right thing single-level index.)

import pandas pd import numpy np  c = ['gbr', 'usa', 'fra'] n = 5 x = pd.dataframe(np.round(np.random.random([n, 3]), 2)) x['from'] = np.random.choice(c, size=n) x['to'] = np.random.choice(c, size=n)  print x     print x.set_index('from').to_latex() print x.set_index(['from', 'to']).to_latex() 

this results in:

      0     1     2   0  0.22  0.45  0.65  gbr  fra 1  0.14  0.30  0.75  gbr  usa 2  0.10  0.92  0.25  fra  usa 3  0.78  0.07  0.55  usa  gbr 4  0.24  0.32  0.28  fra  fra  # table looks fine \begin{tabular}{lrrrl} \toprule {} &     0 &     1 &     2 &   \\ \midrule &       &       &       &      \\ gbr  &  0.22 &  0.45 &  0.65 &  fra \\ gbr  &  0.14 &  0.30 &  0.75 &  usa \\ fra  &  0.10 &  0.92 &  0.25 &  usa \\ usa  &  0.78 &  0.07 &  0.55 &  gbr \\ fra  &  0.24 &  0.32 &  0.28 &  fra \\ \bottomrule \end{tabular}  # look! table shifted down 1 row! \begin{tabular}{llrrr} \toprule     &     &     0 &     1 &     2 \\ \midrule gbr & fra &       &       &       \\     & usa &  0.22 &  0.45 &  0.65 \\ fra &     &  0.14 &  0.30 &  0.75 \\ usa & gbr &  0.10 &  0.92 &  0.25 \\ fra & fra &  0.78 &  0.07 &  0.55 \\ \bottomrule \end{tabular} 


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -