Python 如何使用pandas在latex中输出多索引数据帧?

Python 如何使用pandas在latex中输出多索引数据帧?,python,pandas,latex,Python,Pandas,Latex,我正在尝试使用python和pandas在latex输出中输出多索引数据帧。到目前为止,我有: 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})

我正在尝试使用python和pandas在latex输出中输出多索引数据帧。到目前为止,我有:

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())
但是,我没有预期的输出

                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}

这是一个bug还是我遗漏了什么?

我想这可能是
to\u latex
中的bug。看

根据@PaulH的评论,您可以执行以下操作:

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

这将输出重复的行标签,因此比理想情况下更混乱,但至少它以LaTeX输出整个表。

此问题已提交给pandas,如下问题:。