I'm trying to exclude data that is filtered on another data frame using pandas jupyter. An example of the data frame can be seen below.
Data frame 1:
ID | Amount |
---|---|
AB-01 | 2.65 |
AB-02 | 3.6 |
AB-03 | 5.6 |
AB-04 | 7.6 |
AB-05 | 2 |
Dataframe 2:
ID | Amount |
---|---|
AB-01 | 2.65 |
AB-02 | 3.6 |
Desired outcome:
ID | Amount |
---|---|
AB-03 | 5.6 |
AB-04 | 7.6 |
AB-05 | 2 |
CodePudding user response:
You can use isin
out = df1[~df1['ID'].isin(df2['ID'])]
print(out)
ID Amount
2 AB-03 5.6
3 AB-04 7.6
4 AB-05 2.0