格式化乳胶(to_latex)输出 [英] Formatting latex (to_latex) output

查看:53
本文介绍了格式化乳胶(to_latex)输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读有关 to_latex 方法,但尚不清楚如何使用formatters参数.

我有一些太长的数字,还有一些我想千位分隔符.

I have some numbers which are too long and some which I want thousand separators.

to_latex 的另一面问题多索引表上的方法,将索引解析在一起,并在乳胶输出中发出一些& .

A side issue for the to_latex method on multi-indexed tables, the indices are parsed together and it issues some &s in the latex output.

推荐答案

用于简单的数据框.首先,不使用格式化程序:

For a simple data frame. First, without formatters:

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] 的输出)复制粘贴到乳胶中,我们得到:

Copy-pasting the output (of [12]) to latex, we get:

如果我们创建两个函数 f1 f2 并将它们作为 formatters 放入 to_latex 中:

If we create two functions f1 and f2 and put them into to_latex as formatters:

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}

将输出复制粘贴到乳胶中,我们得到:

注意:格式化程序功能 f1 如何应用于第一列,而 f2 如何应用于第二列.

Note: how the formatter function f1 is applied to the first column and f2 to the second.

这篇关于格式化乳胶(to_latex)输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆