You can use pd.merge()
to perform an anti-join operation which returns only the rows of the left dataframe that are not in the right dataframe based on a specific condition.
Here's an example of how to subset rows from df1
which are not present in df2
based on a condition:
main.py273 chars13 lines
This will output:
main.py24 chars4 lines
Here, we first create two sample dataframes df1
and df2
. We then define the condition as the elements in df1['A']
which are also present in df2['A']
. We use the ~
operator to negate this condition, which gives us the rows in df1
that are not present in df2
.
gistlibby LogSnag