I have a data frame as follows:
Now I want to divide the x by y values without giving me an exception. For example when I divide 3 by 2 it should give me 1.5 and when I divide 3 by 0 it should give me zero. To achieve this I have written an exception function
def divide(x,y):
try:
result = x/y
print (result)
except ZeroDivisionError:
print (0)
I want to now create a new column in the data-frame and apply this function. So far I have used:
df['num'] = df.apply(divide)
But this is not giving me the required result. Can someone help

return x/yinstead of print