小编Oli*_*ier的帖子

如何使用 pandas 在 Latex 中输出多索引 DataFrame?

我正在尝试使用 python 和 pandas 在乳胶输出中输出多索引 DataFrame。到目前为止,我有这个:

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())
Run Code Online (Sandbox Code Playgroud)

但是,我没有预期的输出。

                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 …
Run Code Online (Sandbox Code Playgroud)

python latex pandas

5
推荐指数
1
解决办法
2762
查看次数

标签 统计

latex ×1

pandas ×1

python ×1