Surender Singh
Surender Singh

Reputation: 738

'function' object has no attribute 'apply'

I have a data frame df , which has a column 'query' having text data.

I am trying to clean text data with the help of apply function. But getting the above error. My code is:

def _remove_noise(input_text):
    input_text = str(input_text).encode('ascii', 'ignore')
    input_text = str(input_text).replace(",", "")
    return input_text

when I am calling the above function using the apply function as below:

df['query1'] = df.query.apply(_remove_noise)

It is throwing the error as :

'function' object has no attribute 'apply'

Upvotes: 1

Views: 8936

Answers (1)

jezrael
jezrael

Reputation: 862611

DataFrame.query is pandas function, so need [] for select column query:

df['query1'] = df['query'].apply(_remove_noise)

DataFrame.query is used for filtering, like df.query('col == 1'), so if use df.query.apply it chain query and apply functions and error is raised.

Upvotes: 5

Related Questions