Skip to content Skip to sidebar Skip to footer

How To Filter Dataframe By Splitting Categories Of A Columns Into Sets?

I have a dataframe: Prop_ID Unit_ID Prop_Usage Unit_Usage 1 1 RESIDENTIAL RESIDENTIAL 1 2 RES

Solution 1:

Use in statement in DataFrame.apply:

df = df[~df.apply(lambda x: x['Unit_Usage'] in x['Prop_Usage'], axis=1)]

Or use zip in list comprehension:

df = df[[not a in b for a, b in zip(df['Unit_Usage'], df['Prop_Usage'])]]

print (df)
    Prop_ID  Unit_ID                Prop_Usage   Unit_Usage
1         1        2               RESIDENTIAL   COMMERCIAL
2         1        3               RESIDENTIAL   INDUSTRIAL
4         2        1                COMMERCIAL  RESIDENTIAL
8         3        2                INDUSTRIAL   COMMERCIAL
11        4        3  RESIDENTIAL - COMMERCIAL   INDUSTRIAL
14        5        3  COMMERCIAL / RESIDENTIAL   INDUSTRIAL

Post a Comment for "How To Filter Dataframe By Splitting Categories Of A Columns Into Sets?"