2

I have 2 dataframe pandas df1, df2:

df1 = pd.DataFrame({'col1': ['A', 'B', 'C', 'D'],
                    'col2': ["D1","D2","D3","D4"],
                    'col3': ["C1","C2","C3","C4"],
                    'col4': ["B1","B2","B3","B4"]})


df2 = pd.DataFrame({'col_ID': ['A', 'D']})


df1=
col1 | col2 | col3 | col4
A    | D1   | C1   | B1           
B    | D2   | C2   | B2 
C    | D3   | C3   | B3 
D    | D4   | C4   | B4 

and df2 :

df2=
col_ID |
A      |          
D      | 

and i want to have , the lines in df1.col1 that are not present in df2.col_ID

df1=
col1 | col2 | col3 | col4
B    | D2   | C2   | B2 
C    | D3   | C3   | B3 

thank you for your help

petezurich
  • 9,280
  • 9
  • 43
  • 57
vlad
  • 49
  • 5

1 Answers1

5

isin

df1[~df1.col1.isin(df2.col_ID)]
piRSquared
  • 285,575
  • 57
  • 475
  • 624