removing rows dataframe not in another dataframe using two columns

Solutions on MaxInterview for removing rows dataframe not in another dataframe using two columns by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "removing rows dataframe not in another dataframe using two columns"
Han
05 Jan 2017
1import pandas as pd
2
3USERS = pd.DataFrame({'email':['a@g.com','b@g.com','b@g.com','c@g.com','d@g.com']})
4print (USERS)
5     email
60  a@g.com
71  b@g.com
82  b@g.com
93  c@g.com
104  d@g.com
11
12EXCLUDE = pd.DataFrame({'email':['a@g.com','d@g.com']})
13print (EXCLUDE)
14     email
150  a@g.com
161  d@g.com
17
Eleonora
07 Apr 2019
1df = pd.merge(df1, df2, how='left', indicator='Exist')
2df['Exist'] = np.where(df.Exist == 'both', True, False)
3df = df[df['Exist']==True].drop(['Exist','z'], axis=1)
4