Statsmodel summary_col latex格式错误

时间:2017-03-20 15:58:47

标签: python latex

我正在使用statsmodel的summary_col给我一个输出表,它总结了两个回归输出。

这个代码是

\begin{table}
\caption{}
\begin{center}
    \begin{tabular}{lcc}
        \hline
        & investment I & investment II  \\
        \hline
        \hline
    \end{tabular}
    \begin{tabular}{lll}
        GDP      & 1.35***      & 1.19***        \\
        & (0.24)       & (0.23)         \\
        bsent    & 0.28***      & 0.26***        \\
        & (0.06)       & (0.06)         \\
        rate     & -0.22*       & -0.65***       \\
        & (0.13)       & (0.19)         \\
        research &              & 0.80***        \\
        &              & (0.27)         \\
        R2       & 0.76         & 0.80           \\
        \hline
    \end{tabular}
\end{center}\end{table}

我使用res3.tex文件作为另一个tex文件的输入,然后生成结果。当我使用as_latex()将表转换为LaTeX格式时出现问题。 The table header shifts to the side in the tex file and looks like this.

res3.tex文件具有以下乳胶代码

np.where

由于多个表格环境,似乎出现了问题。有没有办法在不手动更改res3文件(中间文件)的情况下将投资标题放在表格顶部?

1 个答案:

答案 0 :(得分:1)

首先,您必须在Latex的序言中添加一些内容。 在这里您可能会找到问题Outputting Regressions as Table in Python (similar to outreg in stata)?的答案。

res3 = summary_col([res1,res2],stars=True,float_format='%0.2f',
              info_dict={'R2':lambda x: "{:.2f}".format(x.rsquared)})

beginningtex = """\\documentclass{report}
\\usepackage{booktabs}
\\begin{document}"""
endtex = "\end{document}"

f = open('myreg.tex', 'w')
f.write(beginningtex)
f.write(res3.as_latex())
f.write(endtex)
f.close()

所有积分@BKay