Answers for "convert pandas data frame to latex file"

0

convert pandas data frame to latex file

with open('mytable.tex', 'w') as tf:
     tf.write(df.to_latex())
Posted by: Guest on May-26-2020
0

convert pandas data frame to latex file

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}")
Posted by: Guest on May-26-2020

Code answers related to "convert pandas data frame to latex file"

Python Answers by Framework

Browse Popular Code Answers by Language