vendredi 3 juillet 2020

IF Statement in Pandas: Using values from one column (A) to select values from different columns (B or C) an store it in one separate column (D) [duplicate]

My question is: How can I simplify my table with Pandas, to get only one colum with the selected values (the three columns should be one).

Name    Selection   Active  Inactive
A       active      0       0.9
B       active      1       0.8
C       inactive    2       0.7
D       inactive    3       0.6
E       active      4       0.5

Like IF Selection = 'active' THEN Active ELSE Inactive as Selected_Value to get the following result:

Name    Selected_Value
A       0
B       1
C       0.7
D       0.6
E       4 

Thank you very much for you help and code snippets!

Aucun commentaire:

Enregistrer un commentaire