Python:endog已计算为具有多列的数组

Python:endog已计算为具有多列的数组,python,type-conversion,poisson,Python,Type Conversion,Poisson,我尝试运行泊松模型,如下所示: poisson_model_xg = smf.glm(formula="xG ~ home + team + opponent", data=xg_model_data, family=sm.families.Poisson()).fit() 我得到以下错误: ValueError:endog已计算为包含多个列的数组 有形状(760,9)。当变量转换为endog时会发生这种情况 是非数字的(例

我尝试运行泊松模型,如下所示:

poisson_model_xg = smf.glm(formula="xG ~ home + team + opponent", data=xg_model_data, 
                        family=sm.families.Poisson()).fit()
我得到以下错误:

ValueError:endog已计算为包含多个列的数组 有形状(760,9)。当变量转换为endog时会发生这种情况 是非数字的(例如bool或str)

但我不明白这是什么意思,因为我所有的数据帧都是数字:

xg_model_data.apply(lambda s: pd.to_numeric(s, errors='coerce').notnull().all())
Out[10]: 
goals       True
xG          True
team        True
opponent    True
home        True
dtype: bool

解决了。技巧不在内容类型中,而是在列类型中:

xg_model_data.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 760 entries, 0 to 759
Data columns (total 5 columns):
 #   Column    Non-Null Count  Dtype 
---  ------    --------------  ----- 
 0   goals     760 non-null    object
 1   xG        760 non-null    object
 2   team      760 non-null    object
 3   opponent  760 non-null    object
 4   home      760 non-null    object
dtypes: object(5)
memory usage: 55.6+ KB

解决了。技巧不在内容类型中,而是在列类型中:

xg_model_data.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 760 entries, 0 to 759
Data columns (total 5 columns):
 #   Column    Non-Null Count  Dtype 
---  ------    --------------  ----- 
 0   goals     760 non-null    object
 1   xG        760 non-null    object
 2   team      760 non-null    object
 3   opponent  760 non-null    object
 4   home      760 non-null    object
dtypes: object(5)
memory usage: 55.6+ KB