I love vectorization and I have following df
df = pd.DataFrame({'p1':['apple','orange'],
'p1_dog':['True', 'False'],
'p2':['quick','start'],
'p2_dog':['True', 'True'],
'p3':['ash','sword'],
'p3_dog':['False','False']})
Trying to create a new column with values equal p1 or p2 or p3 depends on values in p1_dog and p2_dog and p3_dog.
Using this code:
df['final'] = 0
df['final'] = [[(p1 if p1_dog == p2_dog == p3_dog == True)\
| (p2 if (p1_dog == False) & (p2_dog == p3_dog == True)\
|(p3 if (p1_dog == p2_dog == False) & (p3_dog == True))) for x in df['final']]]
Though it doesn't work... Please help - where is my mistake?