Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multilevel indexing with .to_latex() method merges two index columns #2942

Closed
jobingr opened this issue Feb 27, 2013 · 3 comments
Closed

Multilevel indexing with .to_latex() method merges two index columns #2942

jobingr opened this issue Feb 27, 2013 · 3 comments
Labels

Comments

@jobingr
Copy link

jobingr commented Feb 27, 2013

The to_latex method produces wrong latex code for multi-indexed funds. looks like it are missing a few blank {} and &. Net result is that the current method merges the two indeces. when used with output from pivot_table with major index giving categories and other one details this produces totally garbled results.

The formatters= parameter of to_latex method also creates exceptions for multi-indexed data

@jbzdak
Copy link

jbzdak commented Jun 22, 2015

Sometime before 0.16.2 this bug has transformed. Now there are no "missing {} and &" but data is subtly wrong.

Here is code example:

import pandas as pd 

df = pd.DataFrame([
        {'a': 'a', 'b': 'a', 'c': 'a', 'val': 1},
        {'a': 'a', 'b': 'a', 'c': 'b', 'val': 2},
        {'a': 'a', 'b': 'a', 'c': 'c', 'val': 3},
        {'a': 'c', 'b': 'd', 'c': 'd', 'val': 4},
    ], columns=['a', 'b', 'c', 'val'])

df.set_index(['a', 'b', 'c'], inplace=True)
print(df.to_latex())

Here is output:

\begin{tabular}{lllr}
\toprule
  &   &   &  val \\
\midrule
a & a & a &      \\
  &   & b &    1 \\
  &   & c &    2 \\
c & d & d &    3 \\
\bottomrule
\end{tabular

Notice that val collumn has a blank line in first row, is missing last val and all rows are moved one row down.

@jorisvandenbossche jorisvandenbossche added IO LaTeX to_latex and removed IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string labels Aug 22, 2015
@srib
Copy link
Contributor

srib commented Dec 8, 2015

I think this seems to work okay now.

This is the output I get:

\begin{tabular}{lllr}
\toprule
  &   &   &  val \\
a & b & c &      \\
\midrule
a & a & a &    1 \\
  &   & b &    2 \\
  &   & c &    3 \\
c & d & d &    4 \\
\bottomrule
\end{tabular}

I think this is expected. Maybe we can close this?

@TomAugspurger
Copy link
Contributor

Yep, thanks. Haven't looked too closely, but it looks like #11233 closed it. Thanks @srib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants