0

I was wondering what the best way might be to remove all rows from a dataframe if the values in a field were = to values in a different df.

I have df_1 and df_2. df_2 contains a field called id that contains only ids that I want to remove from df_1 can I perform this doing something thats similar to a merging of df but instead of merging just remove or drop all rows that match df_2?

Thanks :)

Chris90
  • 1,868
  • 5
  • 20
  • 42
  • I think you need `df_1 = df_1[~df_1['col'].isin(df_2['col'])]` – jezrael Mar 11 '19 at 06:23
  • Thanks! So that would give me df_1, with none of the values that exist in df_2? or is that the other way around? Sorry! @jezrael – Chris90 Mar 11 '19 at 06:30
  • Not sure if understand, if not exist no rows are removed? Is possible create [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) if solution not working? – jezrael Mar 11 '19 at 06:31
  • Sorry - I meant I want a df where its basically df_1, but without all rows that exist in df_2 or without all rows that have values in the id col in df_2 @jezrael – Chris90 Mar 11 '19 at 06:33

0 Answers0