I am trying to remove rows whose all values are the same, or a combination of the same values.
I have, for example a dataframe like
data = {'A': ['1, 1, 1', '1', '2', '3', '1'], 'B': ['1', '1,1,1,1', '2', '4', '1'], 'C': ['1, 1', '2', '3', '5', '1']}
I want to remove rows whose values in all columns are '1' or any combination of '1'. The final result should be something like:
data = {'A': ['1', '2', '3'], 'B': ['1,1,1,1', '2', '4'], 'C': ['2', '3', '5']}
I've tried
def remove_rows_with_ones(value):
return all(x == '1' for x in value.split(','))
mask = df.apply(lambda row: any(remove_rows_with_ones(val) for val in row), axis=1)
df_filtered = df[~mask]
But it does not seem to work. Any help is apreciated.