【问题标题】:How should I solve this DataFrame object is not callable error?我应该如何解决这个 DataFrame object is not callable 错误?
【发布时间】: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


    【解决方案1】:

    正如您收到的错误消息所暗示的那样,file 可能是 pandas DataFrame。 在fit_transform() 里面你写过:

    file(['Areas of interest'])
    

    虽然正确的是:

    file['Areas of interest']
    

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

    索引可以通过许多其他方式完成。详情请参阅pandas user manual

    【讨论】:

      猜你喜欢
      • 2019-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 2019-09-17
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      相关资源
      最近更新 更多