-1

How to use the following code in the flask framework, because when I use the following code, always get this error "AttributeError: 'numpy.ndarray' object has no attribute 'apply'"

  message = message.apply(lambda x: ' '.join([word for word in x.split() if len(word) > 4]))
7
  • Does this answer your question? AttributeError: 'numpy.ndarray' object has no attribute 'apply' Commented Oct 20, 2021 at 2:29
  • What is df? df['full_text']? Commented Oct 20, 2021 at 2:38
  • 1
    Looks like df was intended to be a dataframe, but ended up being a dictionary, and df['full_text'] is a numpy array. Commented Oct 20, 2021 at 2:39
  • @3ddavies No. This code is in my model, but I wanted to use this code in the flask framework, but i always get the error AttributeError: 'numpy.ndarray' object has no attribute 'apply'. Is it the flask framework cannot use the 'apply' function ? Commented Oct 20, 2021 at 2:47
  • @hpaulj data frame, this code was in the model, but i want to convert this code into the flask framework, the following is after convert into flask framework message = message.apply(lambda x: ' '.join([word for word in x.split() if len(word) > 4])), but i always getting error Commented Oct 20, 2021 at 2:51

1 Answer 1

0

You are getting the error because numpy.ndarray's do not have an apply attribute (docs). Pandas DataFrames and Series objects have apply. With numpy, you can call np.apply_along_axis but I think this code probably originally expected message to be a pandas Series.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.