Reputation: 3667
I have a df like so:
id answer
1 how are you?
2 What's the word in the letters'
3 .... \xa0 \xa0' Hey what's up?
How do I replace every thing that is not a letter or number with nothing in df.answer?
New df will look like this:
id question
1 how are you
2 Whats the word in the letters
3 Hey whats up
Upvotes: 0
Views: 592
Reputation: 21709
You can also use re
module:
df['answer'] = df['words'].apply(lambda x: re.sub(r'\W+&\s','',x))
Another alternative:
df['words'].str.replace(r'\W+&\s', '')
Upvotes: 0
Reputation: 3399
df.answer = df.apply(lambda row: ''.join(i for i in row.answer if i.isalnum() or i==' '), axis=1)
This should work.
Upvotes: 2