我在列出DataFrame行时遇到问题。下面的函数只返回一行(如果缩进返回第一行,如果没有缩进则返回最后一行)。有谁知道问题出在哪里?
def ols_regression(formula, framedict):
for yp in framedict.keys():
ols_model = ols(formula, framedict[str(yp)]).fit()
year = int(yp[:-5])
params = ols_model.params
d = (dict(yp = yp, year = year, formula=formula, R_squared=ols_model.rsquared,
intercept = params.values[0], DP1 = params.values[1], I = params.values[2], P = params.values[3],
p_intercept = ols_model.pvalues[0], p_DP1 = ols_model.pvalues[1], p_I = ols_model.pvalues[2],
p_P = ols_model.pvalues[3]))
return pd.DataFrame(d, index=[0])
答案 0 :(得分:1)
我通过将字典附加到数组来解决问题。
main