python - Best way to handle ZeroDivisonError? -


i've got following code:

def chunk_trades(a):     last = a[0]     new = []     x in a.iteritems():         if np.abs((x[1]-last)/last) > 0.1:             new.append(x[1])             last = x[1]         else:             new.append(last)     s = pd.series(new, index=a.index)     return s 

sometimes last can zero. in case, i'd carry on gracefully if last zero.

what's cleanest way?

just replace line this:

if not last or np.abs((x[1]-last)/last) > 0.1: 

this not raise exception since left assertion checked first.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -