0

I have a data frame as shown below

Prop_ID    Unit_ID      Prop_Usage      Unit_Usage
1          1            Res             Res
1          2            Res             Com
1          3            Res             Ind
1          4            Res             Res
2          1            Com             Res
2          2            Com             Com
2          3            Com             Com
3          1            Ind             Ind
3          2            Ind             Com

From the above it is clear that one property may have more than 1 units. That means units are the subcategory of properties.

From the above data I want to filter rows where Prop_Usage does not match with Unit_Usage.

Expected Output:

Prop_ID    Unit_ID      Prop_Usage      Unit_Usage
1          2            Res             Com
1          3            Res             Ind
2          1            Com             Res
3          2            Ind             Com
Danish
  • 2,719
  • 17
  • 32

1 Answers1

0

You can achieve this using boolean indexing in combination with the .loc selection from pandas.

df = pd.DataFrame([[5,'Res','Res'],[10,'Res','Com']], columns=['var1','Prop_Usage','Unit_Usage'])


df_filtered = df.loc[df.index[df['Prop_Usage'] != df['Unit_Usage']]]

df_filtered contains then:

 var1 Prop_Usage Unit_Usage
1    10        Res        Com
Pienatt
  • 51
  • 5