mardi 3 novembre 2020

How can I return the value of a column in a new column based on conditions with python

I have a dataframe with three columns

 a b c
[1,0,2] 
[0,3,2] 
[0,0,2] 

and need to create a fourth column based on a hierarchy as follows:

If column a has value then column d = column a

if column a has no value but b has then column d = column b

if column a and b have no value but c has then column d = column c

 a b c d
[1,0,2,1] 
[0,3,2,3] 
[0,0,2,2] 

I'm quite the beginner at python and have no clue where to start.

Aucun commentaire:

Enregistrer un commentaire