📜  将 pandas 数据帧转换为 Latex 文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:23.804000             🧑  作者: Mango

代码示例2
import pandas as pd
df = pd.DataFrame({"a":range(10), "b":range(10,20)})
with open("my_table.tex", "w") as f:
    f.write("\\begin{tabular}{" + " | ".join(["c"] * len(df.columns)) + "}\n")
    for i, row in df.iterrows():
        f.write(" & ".join([str(x) for x in row.values]) + " \\\\\n")
    f.write("\\end{tabular}")