如何将熊猫数据框导出到乳胶表?

对于我的论文,我需要一个较大的数据框作为LaTeX表。 它包含126行和5列。 我知道,有一个功能df.to_latex(buf='citations.tex',largetable=True)。但是,当我运行该函数时,它会在列中剪切我的字符串! 我正在使用jupyter笔记本。因此,当我在此处打印数据框时,列中的字符串会被缩写。没关系但是,当我在数据框上使用to_latex()函数时,这些列也将被缩写。为什么会这样?

我的数据框:

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

使用df.head(2).to_latex()之后 LaTeX输出:

'\\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'

如您所见,textoutput不是数据框的输出,而是印刷版本的输出。即使导出到文件也无济于事。 df.to_latex('citations.tex',longtable=True)是所使用的命令,但无法正常工作。

为什么会发生这种情况,以及如何解决?

woshicgro 回答:如何将熊猫数据框导出到乳胶表?

希望您现在能解决此问题,以防万一...

我遇到了同样的问题,在这里偶然发现了您的帖子。由于先前的解决方案似乎仅适用于在控制台中打印数据帧,而不适用于to_latex函数,因此它对我不起作用。

我在这里找到了这个问题:https://github.com/pandas-dev/pandas/issues/6491,可以使用

为我解决问题
pd.set_option('max_colwidth',1000)

或那里提出的解决方案:

with pd.option_context("max_colwidth",1000):
  print df.to_latex()
,

如果设置以下内容,您的输出是否有所不同:

 import pandas as pd
 pd.set_option('display.max_rows',500)
 pd.set_option('display.max_columns',500)
 pd.set_option('display.width',1000)
本文链接:https://www.f2er.com/3145080.html

大家都在问