Looking for an solution for if else statement in Pandas. Example:
col1 col2
1 NAN
2 NAN
3 NAN
NaN 01-2019
2 NAN
My new column needs to be col3;
- When col1 = 1 or higher, add "text a"
- When col1 = empty and col2 = an value, Take value of col2
- Else; set value "text b"
I have now only; when col1 is higher then 1, set text a, otherwise text b.
df['col3'] = np.where(df['col1']>=1, 'text a', 'text b')
But missing the part where to check if col1 is empty and col2 has an value. To put that value inside col3.
How can i achieve that?
Thanks!
-- EDIT --
Asked also under answer for when col1 = 0 and col2 has an value, to set col3 to the value of col2.
so also:
col1 col2
0 01-2019