Given the following dataframe:
d = {'one': pd.Series([10, 20, 30, 40],
index=['a', 'b', 'c', 'd']),
'two': pd.Series([0, 0, 25, 0],
index=['a', 'b', 'c', 'd'])}
df = pd.DataFrame(d)
one two
a 10 0
b 20 0
c 30 25
d 40 0
How do I select the appropriate value based on the following if/else and populate it into a new column called df['three']
?
df['three'] = If df['two']>0, select df['two'], else select df['one']
Basically, I am looking to have the final result as:
one two three
a 10 0 10
b 20 0 20
c 30 25 25
d 40 0 40