0
考虑多级索引数据帧小号如何将多级索引DataFrame转换为乳胶表(Pandas-Jupyter)?
import numpy as np
import pandas as pd
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
...: ['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
s = pd.DataFrame(np.random.randn(8, 4), index=arrays)
s
我如何可以将其转换为一个不错的表在使用python代码乳胶?
我试图
print s.to_latex()
但失败了,给了我这样的结果
File "<ipython-input-45-d2f4611ecc13>", line 1
print s.to_latex()
^
SyntaxError: invalid syntax
我也试过
s.to_latex()
,结果是不是在所有
'\\begin{tabular}{llrrrr}\n\\toprule\n & & 0 & 1 & 2 & 3 \\\\\n\\midrule\nbar & one & -0.008518 & -0.535653 & -0.603135 & 0.891277 \\\\\n & two & 0.191005 & -1.470384 & 0.697245 & 1.054424 \\\\\nbaz & one & 0.414505 & -0.312967 & 0.703490 & 0.933851 \\\\\n & two & -0.295505 & -0.923843 & -0.423998 & 0.160162 \\\\\nfoo & one & -1.339702 & 0.616059 & 0.519983 & 0.554584 \\\\\n & two & -1.003784 & 0.674981 & 1.609906 & 0.274486 \\\\\nqux & one & -0.139274 & -0.783004 & 1.084794 & 2.202673 \\\\\n & two & -0.730785 & -0.468041 & 0.762726 & -0.532599 \\\\\n\\bottomrule\n\\end{tabular}\n'
举办
非常感谢你这一点,但我期待得到一个正确的标签,你可以在这个标签看到我可能不只是复制它在我的乳胶文件的地方它。例如,它有\ n然后是\ \ toprule,这应该\ n然后\ toprule只有一个\ – rsc05