I am trying to create a new column based on both columns. Say I want to create a new column z, and it should be the value of y when it is not missing and be the value of x when
Use np.where:
np.where
In [3]: df['z'] = np.where(df['y'].isnull(), df['x'], df['y']) df Out[3]: x y z 0 1 NaN 1 1 2 8 8 2 4 10 10 3 8 NaN 8
Here it uses the boolean condition and if true returns df['x'] else df['y']
df['x']
df['y']