Home > Software engineering >  Pandas remove row if email exists in another df [ISSUE]
Pandas remove row if email exists in another df [ISSUE]

Time:01-20

I am trying to make sure that emails from df_unsub are not in prev_month. I have tried everything but it does not seem to remove the email/row from prev_month.

Here is what I have tried:

# Removing Unsubs, New Clients, Duplicates

#1 new_df = prev_month[~prev_month.Email.isin(unsub_list)]
#2 prev_month = prev_month.drop(prev_month[prev_month.Email.isin(unsub_list)].index.tolist())
#3 prev_month = prev_month.query("Email not in @unsub_list")
#4 prev_month = prev_month.query("Email not in @new_clients")
#5 prev_month = prev_month[~prev_month['Email'].isin(unsub_list)]

prev_month = prev_month.drop_duplicates(subset=["Email"])

I am receiving no errors in any other steps.

prev_month df:

Name Email
A.A  [email protected]
B.B  [email protected] <<<
C.C  [email protected]

Unsub_list:

Name Email
G.A  [email protected]
B.B  [email protected] <<<
F.F  [email protected]

The desired output of prev_month:

Name Email
A.A  [email protected]
C.C  [email protected]

CodePudding user response:

Try the following; it should work:

check = prev_month['Email'].isin(unsub_list['Email'])
prev_month.drop(prev_month[check].index, inplace=True)
  •  Tags:  
  • Related