[英]pandas to_latex() escapes mathmode
pandas to_latex()方法似乎是將更大的tabulars轉換為乳膠代碼的便捷方式。 但是,在編寫數學模式時, $
似乎被逃脫了。
一個例子:
import pandas as pd
import numpy as np
table=np.asarray([['$x^2$',3]])
df=pd.DataFrame(table[:,1], columns=['value'], index=table[:,0])
print(df.to_latex(encoding='utf-8'))
輸出:
\begin{tabular}{ll}
\toprule
{} & value \\
\midrule
\$x\textasciicircum2\$ & 3 \\
\bottomrule
\end{tabular}
有沒有辦法防止這種情況發生?
是的,默認情況下,方法的escape參數設置為True。 您可以將其更改為False:
print(df.to_latex(encoding='utf-8', escape=False))
\begin{tabular}{ll}
\toprule
{} & value \\
\midrule
$x^2$ & 3 \\
\bottomrule
\end{tabular}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.