title: handing exceptions based on a particular data frame column
body: <p>I have a data frame as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/HNsXy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HNsXy.png" alt="enter image description here"></a></p>
  
  <p>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</p>
  
  <pre><code>def divide(x,y):
      try:
          result = x/y
          print (result)
      except ZeroDivisionError:
          print (0)
  </code></pre>
  
  <p>I want to now create a new column in the data-frame and apply this function. So far I have used:</p>
  
  <pre><code>df['num']  = df.apply(divide)
  </code></pre>
  
  <p>But this is not giving me the required result. Can someone help</p>