When I am using pandas dataframe, I usually need to do this operation:
x.eq(0).sum()/((x.eq(0)&x.shift().ne(0)).sum())
However, I need to work with arrays, and perform this same function.
I noticed that:
x.eq(0).sum()
Can be written like this in numpy:
np.count_nonzero(x == 0)
This second part ((x.eq(0)&x.shift().ne(0)).sum())
, I don't know which numpy function substitutes shift()
.
How to write this function ((x.eq(0)&x.shift().ne(0)).sum())
on numpy ?