I have a table looking kind of like this - the last one I have added manually to explain wanted outcome
Create one column for breed combining the columns p1-p3 where if true in p1_dog it add p1 value, if false in p1_dog but true in p2_dog add p2 value, if false look in p3_dog and if true add p3 value, else print - 'not a dog'.
I have tried using a for loop and also played around with np.select. Perhaps a np.where should work but dont know how
breeds = []
for row in df_copy:
if ['p1_dog']:
breeds.append(df_copy['p1'])
elif ['p2_dog']:
breeds.append(df_copy['p2'])
elif ['p3_dog']:
breeds.append(df_copy['p3'])
else:
breeds.append('not a dog')
This only give me the full list of values in each stor
Using np.select which I found here pandas if else conditions on multiple columns
This gives me a list of booleans
df_copy['breed'] = np.select([df_copy.p1_dog == True , df_copy.p2_dog == True], [df_copy.p1_dog, df_copy.p2_dog], default=df_copy.p3_dog)