Python 如何解决此DataFrame对象不可调用错误?

Python 如何解决此DataFrame对象不可调用错误?,python,scikit-learn,jupyter-notebook,anaconda,Python,Scikit Learn,Jupyter Notebook,Anaconda,我得到一个错误: ohe = OneHotEncoder(sparse=False) ohe.fit_transform(file(['Areas of interest'])) 正如您得到的错误消息所暗示的,文件可能是一个数据帧。 在fit\u transform()中,您已经编写了: TypeError: 'DataFrame' object is not callable 而正确的答案应该是: file(['Areas of interest']) 第一种情况下的额外括号会导致您收到

我得到一个错误:

ohe = OneHotEncoder(sparse=False)
ohe.fit_transform(file(['Areas of interest']))

正如您得到的错误消息所暗示的,
文件
可能是一个数据帧。 在
fit\u transform()
中,您已经编写了:

TypeError: 'DataFrame' object is not callable
而正确的答案应该是:

file(['Areas of interest'])
第一种情况下的额外括号会导致您收到错误,因为
文件
不是一个函数,而是一个数据帧。 您不调用数据帧(使用括号表示您试图将参数传递给函数),而是通过索引数据帧来访问数据帧的内容(使用方括号
[]
,并将列名作为参数)

索引可以通过许多其他方式完成。有关更多详细信息,请参阅

file['Areas of interest']