Using Python/Pandas (of whatever is best way in python):
What if you want to increment a new column with values such as A1,A2,A3... in the rows (increasing on each row) based on if values are repeating in an existing column such that if the repeating in the existing column ends, column 2 jumps to B1,B2,B3... for the next repeating value (note if next value is not repeating it would simply be B1 and then C1, etc)?
In other words, I have the existing column below and would like to simply add the new column as such:
| Existing Column | New Column |
|---|---|
| 12 | A1 |
| 12 | A2 |
| 12 | A3 |
| 13 | B1 |
| 13 | B2 |
| 14 | C1 |
| 15 | D1 |
| 15 | D2 |
and so forth....
I tried stuff like this which is not really close because
a) it does not start and stop counting based on existing column's values - it simply goes to the end with a single count. b) there is another incrementing or keeping track involved because when one count is done A1,A2,A3 - the next count should start with B (B1, B2, B3) and this means the letter one is one needs to be kept track of for the new column.
list = []
nid = df['note_id']
for i in range(1, df.shape[0] + 1): # gets the length of the DataFrame.
if nid[df[i]] == nid[df[i+1]]:
list.append(f'A{i}')
df['ID'] = list