如何更改statsmodels中的参数函数名称
我想看看在为截距和自变量使用“参数”时,是否有一种方法可以更改输出名称。目标是将其放入以后使用的数据框架中。我知道您可以在使用时更改XNAME model.summary(yname =“ status”,xname = ['alpha','beta'],title ='回归'),但我只希望参数不是整个摘要。
输出
Intercept 125.682063
SP50 -0.288299
dtype: float64
这是我想将其更改为
Alpha 125.682063
Beta -0.288299
dtype: float64
总体代码的
df = pd.read_excel("dataset\Special_Proj.xlsx")
df['Date'] = pd.to_datetime(df['Date'], format='%m/%d/%y')
tickers = ['FDX', 'BRK', 'MSFT', 'NVDA', 'INTC', 'AMD', 'JPM', 'T', 'AAPL', 'AMZN', 'GS']
def rolling_regression_stats():
first52 = df[(df['Date'] <= '2000-12-22')]
for t in tickers:
model = smf.ols(f'{t} ~ SP50', data=first52).fit()
coef_and_intercept = model.params
print(coef_and_intercept,'\n\n')
rolling_regression_stats()
,这是我要实现的目标。
I wanted to see if there was a way to change the output names when using the 'params' for the intercept and independent variable. The goal is to put it into a data frame to use later. I know you can change the xnames when using
model.summary(yname="Status", xname=['Alpha', 'Beta'], title='Regression') but I only want the params not the whole summary.
Here is the output
Intercept 125.682063
SP50 -0.288299
dtype: float64
Here is what I want to change it to
Alpha 125.682063
Beta -0.288299
dtype: float64
Here is the code
df = pd.read_excel("dataset\Special_Proj.xlsx")
df['Date'] = pd.to_datetime(df['Date'], format='%m/%d/%y')
tickers = ['FDX', 'BRK', 'MSFT', 'NVDA', 'INTC', 'AMD', 'JPM', 'T', 'AAPL', 'AMZN', 'GS']
def rolling_regression_stats():
first52 = df[(df['Date'] <= '2000-12-22')]
for t in tickers:
model = smf.ols(f'{t} ~ SP50', data=first52).fit()
coef_and_intercept = model.params
print(coef_and_intercept,'\n\n')
rolling_regression_stats()
Overall, Here is what I'm trying to achieve.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
params
访问者返回pandas.Series
,因此您可以像通常使用系列一样使用它。特别是在代码中,您需要做的就是使用此行:params
accessor returnspandas.Series
, so you can work with it like you usually work with series. Specifically in your code all you need to do is to work with this line: