Reputation: 178
My deliveries dataframe looks like this :
df
Distance
1 10
2 0
3 0
4 3
5 2
6 0
Each time there is a 0, it means the delivery was made at the same place than the previous one. I would like to create a new column "Number of deliveries at this place" that would look like:
df2
Distance Nb_Deliveries
1 10 3
2 0 3
3 0 3
4 3 1
5 2 2
6 0 2
I don't figure out how I could do this group by and count by taking into account the last not null (0) value. Many thanks for your help !
Upvotes: 2
Views: 52