df = pd.DataFrame(dict(name=['Raphael', 'Donatello'],
... mask=['red', 'purple'],
... weapon=['sai', 'bo staff']))
>>> print(df.to_latex(index=False))
egin{tabular}{lll}
oprule
name & mask & weapon
midrule
Raphael & red & sai
Donatello & purple & bo staff
ottomrule
end{tabular}
with open('mytable.tex', 'w') as tf:
tf.write(df.to_latex())
import pandas as pd
df = pd.DataFrame({"a":range(10), "b":range(10,20)})
with open("my_table.tex", "w") as f:
f.write("egin{tabular}{" + " | ".join(["c"] * len(df.columns)) + "}
")
for i, row in df.iterrows():
f.write(" & ".join([str(x) for x in row.values]) + " \
")
f.write("end{tabular}")
df.to_latex(index=False)