Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas multiconditional drop using two dataframes

How can I drop some values from a dataframe using another dataframe as parameter?

df1
code | reply
A1   | yes
A2   | yes
A3   | no

df2
code |
A1   |
A1   |
A3   |

df_new = df1.drop(df1['code'] == df2['code'] AND df1['reply'] != 'yes')

df_new
code | reply
A1   | yes

Is there a simple way to do this using .drop()?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use boolean indexing:

out = df1[df1['code'].isin(df2['code']) & df1['reply'].eq('yes')]

Output:

  code reply
0   A1   yes
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading