[英]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.