I'm trying to create a relationship between repeated ID's in dataframe. For example take 91, so 91 is repeated 4 times so for first 91 entry first column row value will be updated to A and second will be updated to B then for next row of 91, first will be updated to B and second will updated to C then for next first will be C and second will be D and so on and this same relationship will be there for all duplicated ID's. For ID's that are not repeated first will marked as A.
| id | first | other |
|---|---|---|
| 11 | 0 | 0 |
| 09 | 0 | 0 |
| 91 | 0 | 0 |
| 91 | 0 | 0 |
| 91 | 0 | 0 |
| 91 | 0 | 0 |
| 15 | 0 | 0 |
| 15 | 0 | 0 |
| 12 | 0 | 0 |
| 01 | 0 | 0 |
| 01 | 0 | 0 |
| 01 | 0 | 0 |
Expected output:
| id | first | other |
|---|---|---|
| 11 | A | 0 |
| 09 | A | 0 |
| 91 | A | B |
| 91 | B | C |
| 91 | C | D |
| 91 | D | E |
| 15 | A | B |
| 15 | B | C |
| 12 | A | 0 |
| 01 | A | B |
| 01 | B | C |
| 01 | C | D |
I using df.iterrows() for this but that's becoming very messy code and will be slow if dataset increases is there any easy way of doing it.