def id_ramp(a):
    out = np.ones(a.size, dtype=int)
idx = np.nonzero(np.append(True, a[1:] > a[:-1]))[0]
out[idx[1:]] = -idx[1:] + idx[:-1] + 1
return out.cumsum()

def id_ramp2(a):
    out = np.ones(a.size, dtype=int)
idx = np.nonzero(a[1:] > a[:-1])[0] + 1
out[idx[0]] = -idx[0] + 1
out[idx[1:]] = idx[:-1] - idx[1:] + 1
return out.cumsum()
Conditional replacement of row's values in pandas DataFrame