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

时间:2020-07-12 10:30:44

标签: python scikit-learn jupyter-notebook anaconda

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

我遇到了错误:

TypeError: 'DataFrame' object is not callable

1 个答案:

答案 0 :(得分:1)

如您收到的错误消息所暗示,file可能是熊猫DataFrame。 在fit_transform()内部,您已经写过:

file(['Areas of interest'])

正确的方法是:

file['Areas of interest']

在第一种情况下,多余的括号会导致您收到错误,因为file不是函数而是数据帧。 您不调用数据框(使用括号表示您正在尝试将参数传递给函数),而是通过对它们进行索引(使用方括号[](以列名作为参数)来对其进行访问)

可以用许多其他方式来建立索引。有关更多详细信息,请参见pandas user manual