I am using np.select to create a new column based on multiple conditions applied to other columns. Here is a simple example:
df = pd.DataFrame({'A': [0, 3, 4], 'B': [10, 0, 2]})
mask1 = (df['A'] == 0)
mask2 = (df['A'] == 4)
df = df.assign(C = np.select([mask1, mask2], ['Cond1', 'Cond2'], default=np.nan))
Using np.select I am expecting that if neither of the conditions are met I should get an np.nan value in the 'C' column, but when I look for NaNs in the dataframe using df.isna().sum() I don't get any.
I've tried looking this up but I cannot seem to find the answer. What am I missing here?