I need a function to check, row by row, if value is True or False
(df['is_unique_ID'] contains True or False values). If True, it needs to return the (numerical) value of another column df['etp']
def get_etp(self,per_id_u,etp):
if per_id_u is True:
return etp
else:
return "test"
df['new_col'] = df.apply(get_etp,args= (df['is_unique_ID'],df['etp']),axis=1)
unfortunately, that returns a column with only 'test' as values, while I know that df['is_unique_ID'] contains about 4000 True and 250 False
Btw, this is step 1 of a more complicated function, so I would appreciate solutions that keep using the def function and apply , as I will be adding more arguments and elifs later on
Many thanks!
Aucun commentaire:
Enregistrer un commentaire