I have a dataframe that I want to remove duplicate values that are consecutive if their values are 'true' or 'false'. I know how to remove duplicate consecutive rows but not sure how to remove only values that have only values of 'true' or 'false' and not remove all the consecutive duplicate values.
cols =['col_b']
df = df.loc[(df[cols].shift() != df[cols]).any(axis=1)]
For example:
col_a col_b
21 'true'
25 'true'
76 'abc'
89 'ttt'
99 'ttt'
210 'false'
211 'false'
212 'false'
And I need the following result:
col_a col_b
21 'true'
76 'abc'
89 'ttt'
99 'ttt'
210 'false'
but it removes 'ttt' values which I need them.