pandas columns case when equivalent 1

pandas columns case when equivalent

df['c'] = np.select(
[
    (df['a'].isnull() & (df['b'] == 0))
], 
[
    1
], 
default=0 )

Here is what the above code is Doing:
1. Create a new column called ‘c’
2. If column ‘a’ is null and column ‘b’ is equal to 0, then set column ‘c’ to 1
3. If column ‘a’ is not null or column ‘b’ is not equal to 0, then set column ‘c’ to 0

Similar Posts