I have 1 target variable and hundreds of predictor variables. I am trying to run linear regression on one predictor variable at once and then create a dataframe to save all the univariate linear regression results (namely - variable name, p_value) using a for loop.
here are my regression codes in python (X_data has all the predictor variables and y_data has the target variable:
import statsmodels.api as sm
for column in X_Data:
exog = sm.add_constant(X_data[column],prepend = False)
mod = sm.OLS(y_data, exog)
res = mod.fit()
print(column, ' ', res.pvalues[column])
the print results look like:
variable1 0.003
variable2 0.3
...
How can I create a pandas dataframe to save all the p_value results?