'Any Python Library Produces Publication Style Regression Tables
I've been using Python for regression analysis. After getting the regression results, I need to summarize all the results into one single table and convert them to LaTex (for publication). Is there any package that does this in Python? Something like estout in Stata that gives the following table:

Solution 1:[1]
One alternative is Stargazer. To get started quickly, refer to the set of demo tables that Stargazer can produce.
Solution 2:[2]
In addition to @Karl D. 's great answer with Statsmodels as_latex method, you can also check out the pystout package.
!pip install pystout
import pandas as pd
from sklearn.datasets import load_iris
import statsmodels.api as sm
from pystout import pystout
data = load_iris()
df = pd.DataFrame(data = data.data, columns = data.feature_names)
df.columns = ['s_len', 's_w', 'p_len', 'p_w']
y = df['p_w']
X = df[['s_len', 's_w', 'p_len']]
m1 = sm.OLS(y, X).fit()
X = df[['s_len', 's_w']]
m2 = sm.OLS(y, X).fit()
X = df[['s_len']]
m3 = sm.OLS(y, X).fit()
pystout(models=[m1, m2, m3],
file='test_table.tex',
addnotes=['Note above','Note below'],
digits=2,
endog_names=['petal width', 'petal width', 'petal width'],
varlabels={'const':'Constant',
'displacement':'Disp','mpg':'MPG'},
mgroups={'First Group':[1,2],'Second Group':3},
modstat={'nobs':'Obs','rsquared_adj':'Adj. R\sym{2}','fvalue':'F-stat'}
)
Don't spend hours like me trying to print out pystout, the LateX output is directly written on the .tex document you pass for file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | llinfeng |
| Solution 2 | Arthur Langlois |

