Reputation: 69
Assuming I had a tv station dataset, how would I go about creating a generic filter function to filter data from two columns:
My ask is to create a generic function that can be applied to any dataset and then implement the specific criteria to the filter function.
Upvotes: 0
Views: 93
Reputation: 30050
If I understand you correctly, you can do
def filter(df):
m = df['station_call_name'].str.startswith('K|W')
n = df['station_affiliation'].isin(['ABC', 'MBC','BBC'])
return df[m&n]
Upvotes: 1