convert pandas data frame to latex file

Solutions on MaxInterview for convert pandas data frame to latex file by the best coders in the world

showing results for - "convert pandas data frame to latex file"
Silas
28 Sep 2020
1with open('mytable.tex', 'w') as tf:
2     tf.write(df.to_latex())
Jakob
24 Jan 2020
1import pandas as pd
2df = pd.DataFrame({"a":range(10), "b":range(10,20)})
3with open("my_table.tex", "w") as f:
4    f.write("\\begin{tabular}{" + " | ".join(["c"] * len(df.columns)) + "}\n")
5    for i, row in df.iterrows():
6        f.write(" & ".join([str(x) for x in row.values]) + " \\\\\n")
7    f.write("\\end{tabular}")