我收到以下错误;
TypeError Traceback (most recent call last)
<ipython-input-109-d2877618fb0b> in <module>()
3 if cleaned_df[column].dtype == np.number:
4 continue
----> 5 cleaned_df[column] = LabelEncoder.fit_transform(cleaned_df[column])
TypeError: fit_transform() missing 1 required positional argument: 'y'
我的代码如下:
for column in cleaned_df.columns:
if cleaned_df[column].dtype == np.number:
continue
cleaned_df[column] = LabelEncoder.fit_transform(cleaned_df[column])
您必须在
LabelEncoder
后添加括号:
cleaned_df[column] = LabelEncoder().fit_transform(cleaned_df[column])
LabelEncoder 后面缺少 add()。 试试这个:
le=LabelEncoder() for column in cleaned_df.columns: if cleaned_df[column].dtype == np.number: continue cleaned_df[column] = le.fit_transform(cleaned_df[column])
当我们在创建 labelencoder 对象时忘记使用 () 时,就会出现此错误。