I'm making the latex table with pandas, like:
table.to_latex()
However,the output table doesn't contain lines, like "\hline" to make the table with actual. As far as I understand that should happen by default but it doesn't and it is not clear how to do that with options.
Any advice would be appreciated, thanks.
Not that I'm particularly proud of it, but the following solution works:
def latex_with_lines(df, *args, **kwargs):
kwargs['column_format'] = '|'.join([''] + ['l'] * df.index.nlevels
+ ['r'] * df.shape[1] + [''])
res = df.to_latex(*args, **kwargs)
return res.replace('\\\\\n', '\\\\ \\midrule\n')
(and can be easily adapted to support the buf
argument to directly write to file).
Use as
latex_repr = latex_with_lines(df)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With