''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'
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |