I need some help, I want to add a new column from parts of a existing column. I used str.contains but it gives me this error: unsupported operand type(s) for &: 'str' and 'int'
This is my code:
df['VVD'] = df[df['hashtags'].str.contains('rutte', 'mark', 'vvd')]
I know this is not the correct way of doing this but I'm struggling to find out how I can do this.
You are assigning a column to a dataframe!
Try this:
cond = df['hashtags'].str.contains('rutte|mark|vvd')
df['VVD'] = df.loc[cond, 'hashtags']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With