I'm trying to produce a data table for a paper that I can insert into the LaTeX document, using pandas. However, the entries of both the table headers and the elements need to be mathematical formulas in latex ($...$
). In my case, this is because some of them because they have subscripts, and others because all the table values need to have upper and lower error bars, i.e like 0.21^{+0.03}_{-0.05}
etc...
So I made a pandas table with string elements such as '$0.21^{+0.03}_{-0.05}$'
. The dollar signs are there because LaTeX needs to interpret this as a formula as far as I can tell. Unfortunately, when I then try to write the table into latex format with df.to_latex(...)
, the parser puts escape characters \
in front of every dollar sign. The same seems to happen with the underscores, brackets, and all the latex formula characters ('$0.21^{+0.03}_{-0.05}$'
becomes '\$0.21\^\{+0.03\}\_\{-0.05\}$'
How would I be able to block this from happening?
Based on the DataFrame.to_latex
help, you can supply escape = False
(default is True
).
DataFrame.to_latex(escape = False, ...)
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