Making the Beta Dataframe Part 2
Solution
df2 = pd.DataFrame()
for stock in df.columns[:-4]:
frame = regress(stock)
df2 = pd.concat([df2,frame], axis=1)
print(df2)
We do df.columns[:-4] so that we don’t run the regressions on our indicator variables (they’re the last four columns).
Save!
df2.to_csv("RegressionMatrix1.csv",encoding="UTF-8")
Source Code