I'm trying to drop rows which contain certain sub strings in a column. I want to drop all values that contain the sub strings 'Year', 'Monday', '/'
My dataframe looks like:
col1
24/05/2020
May Year 2020
Monday
May 2020
The code I tried:
drop_values = ['Monday','Year', '/']
df = df[~df['Col1'].str.contains(drop_values)]
However I get the following error:
TypeError: unhashable type: 'list'
The Series.str.contains method accepts a regex.
>>> df
col1
0 24/05/2020
1 May Year 2020
2 Monday
3 May 2020
>>> drop_values = ['Monday','Year', '/']
>>> df[~df['col1'].str.contains('|'.join(drop_values))]
col1
3 May 2020
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