Reputation: 643
I'm trying to take the subset of my dataframe that has the same values for an arbitrary amount of columns.
Something like
df[df['col1'] == df['col2'] ==....]
But for an arbitrary amount of column names.
Upvotes: 3
Views: 1159
Reputation: 517
I think this should work
columns_to_compare = ["foo", "bar"]
def check_all_equal(iterator):
return len(set(iterator)) <= 1
df[df[columns_to_compare].apply(lambda row: check_all_equal(row), axis=1)]
Upvotes: 3