[英]Formatting latex (to_latex) output
我已经阅读了关于to_latex
方法的内容,但目前尚不清楚如何使用formatters参数 。
我有一些太长的数字,有些我想要一千个分隔符 。
对于多索引表的to_latex
方法的一个侧面问题 ,索引被一起解析并在latex输出中发出一些&
s。
对于简单的数据框架。 首先,没有格式化程序:
In [11]: df
Out[11]:
c1 c2
first 0.821354 0.936703
second 0.138376 0.482180
In [12]: print df.to_latex()
\begin{tabular}{|l|c|c|c|}
\hline
{} & c1 & c2 \\
\hline
first & 0.821354 & 0.936703 \\
second & 0.138376 & 0.482180 \\
\hline
\end{tabular}
将输出( [12]
)复制粘贴到乳胶中,我们得到:
如果我们创建两个函数f1
和f2
并将它们作为formatters
放入to_latex
:
def f1(x):
return 'blah_%1.2f' % x
def f2(x):
return 'f2_%1.2f' % x
In [15]: print df.to_latex(formatters=[f1, f2])
\begin{tabular}{|l|c|c|c|}
\hline
{} & c1 & c2 \\
\hline
first & blah\_0.82 & f2\_0.94 \\
second & blah\_0.14 & f2\_0.48 \\
\hline
\end{tabular}
将输出复制粘贴到latex,我们得到:
注意:格式化程序函数f1
如何应用于第一列, f2
应用于第二列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.