I have a DataFrame with 3 columns that represent the same data (the name of a person). The columns are Username
, BuyerName
, TravelerName
. In some cases, these three columns can share the same value (the username is the same person who bought a ticket and used it to travel, for instance), and I want to exclude/filter these cases. Here is my current working code:
def filter_df(df, user_name):
filtered_df = df.query(f'Username != "{user_name}" & BuyerName != "{user_name}" & TravelerName != "{user_name}")
return filtered_df
I'd like to know if there is a cleverer way of doing this query instead of just repeating the same value over and over the columns.