【发布时间】:2022-08-08 20:20:54
【问题描述】:
我正在尝试将 pandas 数据帧转换为乳胶格式,但它在输出中返回了额外的斜杠。
数据
df = pd.DataFrame({\'model_name\': {0: \'ALBERT\', 1: \'a\', 2: \'b\', 3: \'c\', 4: \'d\', 5: \'e\'}, \'macro_precision_first\': {0: 91.89396817624747, 1: 92.17133890858452, 2: 92.6826295632407, 3: 92.80299948526579, 4: 93.34410168004217, 5: 92.0346638078341}, \'macro_recall_first\': {0: 92.2318448502444, 1: 92.3357692328841, 2: 93.0292033013862, 3: 93.12015088280738, 4: 93.66748596470968, 5: 92.36958589707638}, \'macro_f1_first\': {0: 91.95372391665576, 1: 92.23312713937592, 2: 92.71221623765801, 3: 92.88621653320901, 4: 93.43123707996612, 5: 92.1035266749227}})
当我尝试df.to_latex() 时,输出如下所示:
\'\\\\begin{tabular}{llrrr}\\n\\\\toprule\\n{} & model\\\\_name & macro\\\\_precision\\\\_first & macro\\\\_recall\\\\_first & macro\\\\_f1\\\\_first \\\\\\\\\\n\\\\midrule\\n0 & ALBERT & 91.89 & 92.23 & 91.95 \\\\\\\\\\n1 & a & 92.17 & 92.34 & 92.23 \\\\\\\\\\n2 & b & 92.68 & 93.03 & 92.71 \\\\\\\\\\n3 & c & 92.80 & 93.12 & 92.89 \\\\\\\\\\n4 & d & 93.34 & 93.67 & 93.43 \\\\\\\\\\n5 & e & 92.03 & 92.37 & 92.10 \\\\\\\\\\n\\\\bottomrule\\n\\\\end{tabular}\\n\'
我期待的是这样的行:
ALBERT & 91.89 & 92.23 & 91.95 \\\\
a & 92.17 & 92.34 & 92.23 \\\\
b & 92.68 & 93.03 & 92.71 \\\\
c & 92.80 & 93.12 & 92.89 \\\\
d & 93.34 & 93.67 & 93.43 \\\\
e & 92.03 & 92.37 & 92.10 \\\\
我怎样才能摆脱多余的斜线和\\\\\\n?
标签: python pandas dataframe latex