I have the following data:
a = pd.Series([1, 2, 3]) b = pd.Series([0, 0, 0])
If there is a division by zero I want to in some cases
You can also use the np.isinf function to check for infinite values and then substitue them with 0. Ex-
np.isinf
a = np.asarray(np.arange(5)) b = np.asarray([1,2,0,1,0]) c = a/b c[np.isinf(c)] = 0 #result >>> c array([ 0. , 0.5, 0. , 3. , 0. ])