0
我目前正在從一個數據框(稱爲df)跨不同的因變量運行迴歸。我想知道如何在48迴歸中做出迴應。這個函數的非環狀的版本如下:如何使循環跨數據框python執行迴歸
agric_ff = ols(formula = 'agric ~ prem + smb + hml', data=df).fit()
agric_ff_df = pd.DataFrame({'params': agric_ff.params})
agric_ff_df.columns = ['agric']
food_ff = ols(formula = 'food ~ prem + smb + hml', data=df).fit()
food_ff_df = pd.DataFrame({'params': food_ff.params})
food_ff_df.columns = ['food']
soda_ff = ols(formula = 'soda ~ prem + smb + hml', data=df).fit()
soda_ff_df = pd.DataFrame({'params': soda_ff.params})
soda_ff_df.columns = ['soda']
beer_ff = ols(formula = 'beer ~ prem + smb + hml', data=df).fit()
beer_ff_df = pd.DataFrame({'beer': beer_ff.params})
beer_ff_df.columns = ['beer']
smoke_ff = ols(formula = 'smoke ~ prem + smb + hml', data=df).fit()
smoke_ff_df = pd.DataFrame({'smoke': smoke_ff.params})
smoke_ff_df.columns = ['smoke']
toys_ff = ols(formula = 'toys ~ prem + smb + hml', data=df).fit()
toys_ff_df = pd.DataFrame({'toys': toys_ff.params})
toys_ff_df.columns = ['toys']
fun_ff = ols(formula = 'fun~ prem + smb + hml', data=df).fit()
fun_ff_df = pd.DataFrame({'fun': fun_ff.params})
fun_ff_df.columns = ['fun']
books_ff = ols(formula = 'books ~ prem + smb + hml', data=df).fit()
books_ff_df = pd.DataFrame({'books': fun_ff.params})
books_ff_df.columns = ['books']
使用公式符號一種方法你的幫助是非常讚賞