【问题标题】:How to fix this error :AttributeError: 'numpy.ndarray' object has no attribute 'apply'如何修复此错误:AttributeError:“numpy.ndarray”对象没有属性“apply”
【发布时间】:2021-10-20 02:28:05
【问题描述】:

如何在flask框架中使用下面的代码,因为我在使用下面的代码时,总是报这个错误“AttributeError: 'numpy.ndarray' object has no attribute 'apply'”

  message = message.apply(lambda x: ' '.join([word for word in x.split() if len(word) > 4]))

【问题讨论】:

  • 什么是dfdf['full_text']?
  • 看起来 df 本来是一个数据框,但最终成为了一个字典,而 df['full_text'] 是一个 numpy 数组。
  • @3ddavies 否。此代码在我的模型中,但我想在烧瓶框架中使用此代码,但我总是收到错误 AttributeError: 'numpy.ndarray' object has no attribute 'apply '。是不是flask框架不能使用'apply'功能?
  • @hpaulj 数据框,此代码在模型中,但我想将此代码转换为flask框架,以下是转换为flask框架后的消息 = message.apply(lambda x: ' '.join([word for word in x.split() if len(word) > 4])),但我总是出错

标签: python python-3.x numpy text preprocessor


【解决方案1】:

您收到错误是因为 numpy.ndarray 没有 apply 属性 (docs)。 Pandas DataFramesSeries 对象具有 apply。使用 numpy,您可以调用 np.apply_along_axis,但我认为这段代码最初可能预期 message 是熊猫 Series

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-11
    • 2020-12-03
    • 2020-11-29
    • 2020-10-06
    • 2018-01-25
    • 2016-06-29
    • 2020-03-25
    相关资源
    最近更新 更多