Given a Series , I would like to efficiently compute how many observations have passed since there was a change. Here is a simple example:
Series
ser = pd.
You can use groupby.cumcount:
groupby.cumcount
ser.groupby(ser).cumcount() #0 0 #1 1 #2 2 #3 3 #4 0 #5 1 #6 2 #7 0 #8 0 #dtype: int64