I've got the following code:
def chunk_trades(A):
last = A[0]
new = []
for 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 be zero. In this case, I'd like it to just carry on gracefully as if last
was almost zero.
What's the cleanest way?