I combined three dataframes that have multiple email
columns, then renamed the columns for ease of scripting. I'm trying to create a master email column based on conditions. If C
is populated, use C
. If not, and B
is populated, use B
. If not, and A
is populated, use A
. For some reason it's only filling in the master column if C
is populated. Even if A
is populated, it's returning a null value.
dfs = [df_A, d365, df_C]
from functools import reduce
dfFinal = reduce(lambda left,right: pd.merge(left,right,on='leadId'), dfs)
import numpy as np
emailconditions = [
dfFinal['EmailC'] is not None,
(dfFinal['EmailC'] is None) & (dfFinal['EmailB'] is not None),
(dfFinal['EmailC'] is None) & (dfFinal['EmailB'] is None)]
emailvalues = [
dfFinal['EmailC'],
dfFinal['EmailB'],
dfFinal['EmailA']]
dfFinal['emailFinal'] = np.select(emailconditions, emailvalues)