0

for my thesis, I need a large dataframe as a LaTeX table. It contains 126 rows and 5 columns. I know, that there is a function df.to_latex(buf='citations.tex', largetable=True). However, when i run the function, it cuts of my strings in the columns! I am using jupyter notebook. So when i print my dataframe there, the strings in the columns get abbreviated. This is all right. But when I use the to_latex() function on my dataframe, the columns get abbreviated as well. Why is this happening?

My Dataframe:

title authors journal year doi A visualization and modeling tool for security... Reijo M. Savola; Petri Heinonen 2011 Information Security for South Africa 2011 10.1109/ISSA.2011.6027518 Information security requirements – Interpreti... Mariana Gerber; Rossouw von Solms Computers & Security 2008 https://doi.org/10.1016/j.cose.2008.07.009 

After using df.head(2).to_latex() The LaTeX output:

'\\begin{tabular}{llllrl}\n\\toprule\n{} & title & authors & journal & year & doi \\\\\n\\midrule\n0 & A visualization and modeling tool for security... & Reijo M. Savola; Petri Heinonen & 2011 Information Security for South Africa & 2011 & 10.1109/ISSA.2011.6027518 \\\\\n1 & Information security requirements – Interpreti... & Mariana Gerber; Rossouw von Solms & Computers \\& Security & 2008 & https://doi.org/10.1016/j.cose.2008.07.009 \\\\\n\\bottomrule\n\\end{tabular}\n' 

As you can see, the textoutput is not an output of the dataframe, but rather from the printed version. Even exporting to a file, doesn't help. df.to_latex('citations.tex', longtable=True) is the command used, but it doesn't work as expected.

Why is this happening, and how to fix it?

2 Answers 2

2

I hope you managed to solve this by now, but just in case...

I had the same problem and stumbled upon your post here. As the previous solution only seems to apply for printing dataframes in the console, but not in the to_latex function, it didn't work for me.

I found this issue here: https://github.com/pandas-dev/pandas/issues/6491 and could solve the problem for me using

pd.set_option('max_colwidth', 1000) 

or the solution proposed there:

with pd.option_context("max_colwidth", 1000): print df.to_latex() 
Sign up to request clarification or add additional context in comments.

1 Comment

Its a long time ago. When I have the time, I'll try to recreate your solution and see if it works. Thanks
0

Do you see a difference on your output if you set this:

 import pandas as pd pd.set_option('display.max_rows', 500) pd.set_option('display.max_columns', 500) pd.set_option('display.width', 1000) 

2 Comments

Nope, it stays the same. Columns get still abreviated, no matter if I use df.head(), df.head().to_latex or df
you can check this link

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.