Statsmodel摘要库ZeroDivisionError:

时间:2018-06-21 10:02:26

标签: python statsmodels divide-by-zero

我知道ZeroDivisionError是什么意思,但是有没有办法解决Statmodel摘要库中的此错误? 这是我的当前代码:

# import modules
import pandas as pd
import statsmodels.formula.api as smf
import numpy as np
from statsmodels.iolib.summary2 import summary_col
df = pd.read_csv(input_file, nrows=500)
mod = smf.ols(formula='lnq ~ lnp + lnp:C(product_code)+ C(product_code)', data=df)
res = mod.fit(cov_type = 'cluster', cov_kwds={'groups': df['product_code']})
print(res.summary())



info_dict={'R-squared' : lambda x: f"{x.rsquared:.2f}",
           'No. observations' : lambda x: f"{int(x.nobs):d}"}

results_table = summary_col(results=[res],
                            float_format='%0.2f',
                            stars = True,
                            model_names=['Model 1'],
                            info_dict=info_dict)

results_table.add_title('Table  - OLS Regressions')
print(results_table)

这是我得到的错误:

  File "C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\iolib\summary2.py", line 237, in _measure_tables
    pad = int((len_max - length[i]) / nsep)

ZeroDivisionError: division by zero

0 个答案:

没有答案