从大 pandas DataFrame导出LaTeX表 [英] Export a LaTeX table from pandas DataFrame
本文介绍了从大 pandas DataFrame导出LaTeX表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有简单的方法将数据框架(或甚至其一部分)导出到LaTeX?
Is there an easy way to export a data frame (or even a part of it) to LaTeX?
我在谷歌搜索,只能使用asciitables找到解决方案。
I searched in google and was only able to find solutions using asciitables.
推荐答案
DataFrames有一个 to_latex
方法:
DataFrames have a to_latex
method:
In [42]: df = pd.DataFrame(np.random.random((5, 5)))
In [43]: df
Out[43]:
0 1 2 3 4
0 0.886864 0.518538 0.359964 0.167291 0.940414
1 0.834130 0.022920 0.265131 0.059002 0.530584
2 0.648019 0.953043 0.263551 0.595798 0.153969
3 0.207003 0.015721 0.931170 0.045044 0.432870
4 0.039886 0.898780 0.728195 0.112069 0.468485
In [44]: print df.to_latex()
\begin{tabular}{|l|c|c|c|c|c|c|}
\hline
{} & 0 & 1 & 2 & 3 & 4 \\
\hline
0 & 0.886864 & 0.518538 & 0.359964 & 0.167291 & 0.940414 \\
1 & 0.834130 & 0.022920 & 0.265131 & 0.059002 & 0.530584 \\
2 & 0.648019 & 0.953043 & 0.263551 & 0.595798 & 0.153969 \\
3 & 0.207003 & 0.015721 & 0.931170 & 0.045044 & 0.432870 \\
4 & 0.039886 & 0.898780 & 0.728195 & 0.112069 & 0.468485 \\
\hline
\end{tabular}
你可以简单的写一个tex文件。
You can simply write this to a tex file.
默认情况下,latex将会呈现为:
By default latex will render this as:
img src =https://i.stack.imgur.com/W4Mqu.pngalt =,因为它会出现在乳胶>
注意: to_latex
方法提供了多种配置选项。
Note: the to_latex
method offers several configuration options.
这篇关于从大 pandas DataFrame导出LaTeX表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文