当我将 pandas(版本 1.4.3)数据帧导出到乳胶代码时,我试图删除行编号。我发现我应该包含命令“index=False”。但是,当我运行代码时,出现错误,提示样式器不包含“索引”。
错误代码:
File "/home/-/GitHub/-/latex/step1_feet_bottom.py", line 43, in get_feet
excel = excel.to_latex(index=False,
TypeError: Styler.to_latex() got an unexpected keyword argument 'index'
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
latex = df.copy()
latex = latex.round(1)
latex = latex.style.format(na_rep='-', precision=1)
latex = latex.to_latex(index=False,
column_format="rrrrr", position="h", position_float="centering",
hrules=True, label="table:5", caption="Styled LaTeX Table",
multirow_align="t", multicol_align="r"
)
print(latex)
Run Code Online (Sandbox Code Playgroud)
以下是一件奇怪的事情,如果我在 to_latex 中包含 na_rep='-' ,我会得到同样的错误。我的第一个猜测是我正在运行旧版本的 pandas,但是我正在运行最新版本 1.4.3
先感谢您。