How to output a multi-index DataFrame in latex with pandas?
Question: I am trying to output a multi-index DataFrame in a latex output using python
and pandas. So far, I have this:

    
    
    import pandas as pd
    
    l = []
    for a in ['1', '2', '3']:
        for b in ['first', 'second']:
            for c in ['one', 'two']:
                x = 3.2
                s = pd.Series({'a':a, 'b':b, 'c':c, 'x':x})
                l.append(pd.DataFrame(s).transpose())
    
    df = pd.concat(l, ignore_index=True)
    df = df.set_index(['a', 'b', 'c'])
    print(df)
    print(df.to_latex())
    

However, I do not have the expected output.

    
    
                    x
    a b      c       
    1 first  one  3.2
             two  3.2
      second one  3.2
             two  3.2
    2 first  one  3.2
             two  3.2
      second one  3.2
             two  3.2
    3 first  one  3.2
             two  3.2
      second one  3.2
             two  3.2
    \begin{tabular}{llll}
    \toprule
    
      &       &     &    x \\
    \midrule
    1 & first & one &      \\
    2 & second & two &  3.2 \\
    \bottomrule
    \end{tabular}
    

Is this a bug or is there something I missed?


Answer: I think this may be a bug in `to_latex`. See [this
question](http://stackoverflow.com/questions/25734454/nbconvert-multiindex-
dataframes-to-latex).

Based on @PaulH's comment, you could do the following:

    
    
    df.reset_index().to_latex(index=False)
    

That will output repeated row labels, so it's more cluttered than would be
ideal, but at least it outputs the whole table in LaTeX.

