【发布时间】:2020-07-12 10:30:44
【问题描述】:
ohe = OneHotEncoder(sparse=False)
ohe.fit_transform(file(['Areas of interest']))
我收到错误:
TypeError: 'DataFrame' object is not callable
【问题讨论】:
标签: python scikit-learn jupyter-notebook anaconda
ohe = OneHotEncoder(sparse=False)
ohe.fit_transform(file(['Areas of interest']))
我收到错误:
TypeError: 'DataFrame' object is not callable
【问题讨论】:
标签: python scikit-learn jupyter-notebook anaconda
正如您收到的错误消息所暗示的那样,file 可能是 pandas DataFrame。
在fit_transform() 里面你写过:
file(['Areas of interest'])
虽然正确的是:
file['Areas of interest']
第一种情况下的额外括号会导致您收到错误,因为file 不是函数而是数据框。
您不调用数据框(使用括号表示您正在尝试将参数传递给函数),但您通过索引它们来访问它们的内容(使用方括号 [] 并将列名作为参数)。
索引可以通过许多其他方式完成。详情请参阅pandas user manual。
【讨论】: