I have a dataframe column with numbering like this:
| week |
| -------- |
| 10 |
| 11 |
| 12 |
| 14 |
| 15 |
| 16 |
| 18 |
| 19 |
| 20 |
| 21 |
and I wanna get this (a new column 'nums' with sequential numbering on contiguous blocks of 'week'):
| week | nums |
| -------- | -------------- |
| 10 | 0 |
| 11 | 1 |
| 12 | 2 |
| 14 | 0 |
| 15 | 1 |
| 16 | 2 |
| 18 | 0 |
| 19 | 1 |
| 20 | 2 |
| 21 | 3 |
| ... | ... |
Any ideas how to realize it as fast as possible without iteration because it's over a million rows.
And then I need a) just to count each that block of nums column and b) calculate median of 'nums' for each block