I have a bunch of words I want to replace to ""
. I put them in a list:
noise = [a,b,c,...]
Example dataset:
column1
I want a car
Becomes:
column1
I wnt cr
How can I use the list to iterate over in replace
function.
This is my current code :
df[columnA] = df[columnA].str.replace((x for x in noise), "")
But I keep getting error.. I have to apply the same list to several other columns as well. So I'm looking for a shorter way to do this and avoiding apply
function.
Error:
TypeError: object of type 'generator' has no len()
If add len(noise)
, I'll get this error:
TypeError: 'int' object is not iterable