Pandas error when using if-else to create new column: The truth value of a Series is ambiguous

What about doing

>>> df['C'] = np.where(df.B>0., df.A/df.B, 0.)

which reads as :

where df.B is strictly positive, return df.A/df.B, otherwise return 0.

Leave a Comment