jeudi 23 juillet 2020

If Statement where column contains a certain value [duplicate]

df1 = Profit, Qualified 1000, TRUE 2000, FALSE 3000, FALSE 4000, TRUE

Desired output:

df1= Profit, Qualified, Qualified Profit 1000, TRUE, 1000 2000, FALSE, 0 3000, FALSE, 0 4000, TRUE, 4000

Two lines of code i have tried: df1['Qualified Profit'] = df1['Profit'].where(df1['Qualified'] == "TRUE")

df1['Qualified Profit'] = df1.apply(lambda x: x['Profit'] if x["Qualified"]=="TRUE" else '0', axis=1)

Aucun commentaire:

Enregistrer un commentaire