I have to delete values in row of a dataframe if they contain a certain string. Problem is that row is very long and contains text.
Loop does not work and put index in a list and then use .drop on index does also not work.
column1
8
8
8
8 total <-------- This must be deleted
8
8
8
8
8
...
Thanks
Suppose your dataframe is called df. Then use:
df_filtered = df[~df['column1'].str.contains('total')]
Explanation:
df['column1'].str.contains('total') will give you an array of the length of the dataframe column that is True whereever df['column1'] contains 'total'. With ~ you swap the True and False values of this array. And finally with df_filtered = df[...] you take only the lines, for which 'total' is not included.
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