【发布时间】:2015-06-22 21:42:35
【问题描述】:
我正在尝试使用 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())
但是,我没有预期的输出。
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}
这是一个错误还是我错过了什么?
【问题讨论】:
-
这个 issue 已经提交给 pandas,如下 issue:github.com/pydata/pandas/issues/2942.