0

I have two data frames df_semi_sup2 and df_confident_inst_no and I want to drop all instances existing in df_confident_inst_no from df_semi_sup2. I made researches about that and I found the necessary code, but it dosen't give the results that I'm waiting for.

Here is the code :

for index, row in df_confident_inst_no.iterrows() :

    df_semi_sup2= df_semi_sup2.drop(df_semi_sup2.index[index])

Can anyone help me find the problem in such code ?

Thanks!

Mari
  • 69
  • 1
  • 8
  • Possible duplicate of [pandas get rows which are NOT in other dataframe](https://stackoverflow.com/questions/28901683/pandas-get-rows-which-are-not-in-other-dataframe) – sudonym Jun 27 '18 at 22:18

1 Answers1

1

See here (works if data structure is identical which you don't tell us):

df_new = df_semi_sup2[~df_semi_sup2.isin(df_confident_inst_no)].dropna() # No need to loop

You can use dropna()'s how parameter like so:

‘any’ : If any NA values are present, drop that row or column.

‘all’ : If all values are NA, drop that row or column.

KLDavenport
  • 659
  • 8
  • 24
sudonym
  • 3,788
  • 4
  • 36
  • 61
  • 1
    Yes in fact data structure is identical. Your answer solved the problem perfectly ! Thanks! – Mari Jun 27 '18 at 22:58