title: Bypass error Division by zero when doing a loop - Python
body: <p>New using Python :) I am trying to normalise my data using different columns however, it sometimes occur that some columns I am using to make division have value = 0. Which then give me error: ZeroDivisionError by zero.</p>
  
  <p>I have one dataframe mergedfs and loop through columns to calculate normalised values.</p>
  
  <pre><code>b = 0
  w = (len(files))+1 #number depending on how many csv files I have. This will determine which columns index I will use.
  while b &lt; len(files):
      b += 1
      if b == 1:
          w += 1
          mergedfs.insert(len(files)+1+b, 'NHAF R{}'.format(b), np.log10((((mergedfs.ix[:,b] / mergedfs.ix[:,w])/106)/((mergedfs.ix[:,b].sum() / (mergedfs.ix[:,w].sum())/106)) / sum(((mergedfs.ix[:,b] / mergedfs.ix[:,w])/106)/((mergedfs.ix[:,b].sum() / (mergedfs.ix[:,w].sum())/106))))))
      else:
           w += 2
           mergedfs.insert(len(files)+1+b, 'NHAF R{}'.format(b), np.log10(((mergedfs.ix[:,b] / mergedfs.ix[:,w])/106)/((mergedfs.ix[:,b].sum() / (mergedfs.ix[:,w].sum())/106)) / sum(((mergedfs.ix[:,b] / mergedfs.ix[:,w])/106)/((mergedfs.ix[:,b].sum() / (mergedfs.ix[:,w].sum())/106)))))
  </code></pre>
  
  <p>The ZeroDivisionError by zero is usually because sometimes. mergedfs.ix[:,b] AND mergedfs.ix[:,b] will be equal to 0.</p>
  
  <p>Is there a way to bypass it?</p>
  
  <pre><code>I have tried np.log10((((mergedfs.ix[:,b] / mergedfs.ix[:,w])/106)/((mergedfs.ix[:,b].sum() / (mergedfs.ix[:,w].sum())/106)) / sum(((mergedfs.ix[:,b] / mergedfs.ix[:,w])/106)/((mergedfs.ix[:,b].sum() / (mergedfs.ix[:,w].sum())/106)))).where(mergedfs.ix[:,b] != 0)
  </code></pre>
  
  <p>However, no success.</p>
  
  <p>I have searched for quite a while on stackoverflow and most didn't work on my code. </p>
  
  <p>Thanks a lot if you can guide me a bit to solve this problem.</p>
  
  <p>Cheers !</p>