AttributeError:“ SimpleTable”对象没有属性“ column”

我正在尝试将多个回归模型的摘要导出到表中。

results = {'A':result.summary(),'B': result1.summary(),'C': result2.summary(),'D': result3.summary(),'E' : result4.summary()}
df2 = pd.DataFrame({'Model':[],'Param':[],'Value':[]})
for mod in results.keys():
    for col in results[mod].tables[0].columns:
        if col % 2 == 0: 
            df2 = df2.append(pd.DataFrame({'Model': [mod]*results[mod].tables[0][col].size,'Param':results[mod].tables[0][col].values,'Value':results[mod].tables[0][col+1].values}))

print(df2)

当我运行代码时,它给我错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-280-952fff354224> in <module>
      3 df2 = pd.DataFrame({'Model':[],'Value':[]})
      4 for mod in results.keys():
----> 5     for col in results[mod].tables[0].column:
      6         if col % 2 == 0:
      7             df2 = df2.append(pd.DataFrame({'Model': [mod]*results[mod].tables[0][col].size,AttributeError: 'Simpletable' object has no attribute 'column'
jsz0728 回答:AttributeError:“ SimpleTable”对象没有属性“ column”

很难不知道自己如何创建result.summary()等,但是SimpleTable API可能遵循类似/相关的熊猫API,在这种情况下,您正在寻找{ {1}}属性(注意复数“ s”)。

,

这里的 SimpleTable 是 statsmodels.iolib.table.SimpleTableenter link description here。我们可以使用 pandas.DataFrame.from_records 将数据类型转换为 DataFrame。从这里,您可以轻松访问列。

确保通过名为“t”的变量访问这个 SimpleTable

df = pd.DataFrame.from_records(t.data)
header = df.iloc[0] # grab the first row for the header
df = df[1:] # take the data less the header row
df.columns = header
print(df.shape)
return df['your_col_name']
本文链接:https://www.f2er.com/3131214.html

大家都在问