Reputation: 71
I am trying to use the preprocessor library in order to clean text stored in a Pandas Data Frame. I've installed the last version (https://pypi.org/project/tweet-preprocessor/), but I receive this error message:
import preprocessor as p
#forming a separate feature for cleaned tweets
for i,v in enumerate(df['text']):
df.loc[v,'text'] = p.clean(i)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-183-94e08e1aff33> in <module>
1 #forming a separate feature for cleaned tweets
2 for i,v in enumerate(df['text']):
----> 3 df.loc[v,'text'] = p.clean(i)
AttributeError: module 'preprocessor' has no attribute 'clean'
Upvotes: 3
Views: 7032
Reputation: 600
You probably have the preprocessor
module installed as well, which is entirely distinct from the tweet-preprocessor
module. However, confusingly, the import preprocessor as p
statement can be used for both. When both modules are installed, Python ignores tweet-preprocessor
and automatically opts for preprocessor
, which does not contain a clean
function, hence the error you received.
To resolve this, I had to uninstall both modules with the following commands:
pip uninstall preprocessor
pip uninstall tweet-preprocessor
Then I closed all shells for a fresh start and typed:
pip install tweet-preprocessor
And finally:
>>> import preprocessor as p
>>> p.clean('#this and that')
'and that'
Merely uninstalling preprocessor
did not work. Python kept importing the module despite it being uninstalled. I am not sure why, but I suspect it has something to do with caches that Python keeps in the background.
Upvotes: 5
Reputation: 21
Try installing first:
pip install tweet-preprocessor
Then:
import preprocessor as p
Upvotes: 2