I have a list of values in a column (A) and want to increment by 1 in column (B) until the value in A changes, however, having difficulty in my loop to reset the increment when A changes.
B = []
list_length = len(A)
for i in range(0, list_length):
j = 1
while A[i] == A[i+1]:
B = j
j += 1
i += 1
else:
B = 1
j += 1
Here is desired output:
| Product(A) | No.(B) |
|---|---|
| Apple | 1 |
| Apple | 2 |
| Apple | 3 |
| Orange | 1 |
| Orange | 2 |
| Orange | 3 |
| Orange | 4 |
| Orange | 5 |
| Orange | 6 |
| Melon | 1 |
| Melon | 2 |
| Peach | 1 |
| Peach | 2 |
| Peach | 3 |
| Peach | 4 |