I have a dataframe with multiple rows per index and want to reset the count of the index but keeping the same multiple rows per index.
Example:
| Name |
1234 | AA |
1234 | AB |
1235 | BA |
1235 | BB |
1236 | CA |
1236 | CB |
1237 | DA |
I'm trying to have something such as:
| Name |
1 | AA |
1 | AB |
2 | BA |
2 | BB |
3 | CA |
3 | CB |
4 | DA |
CodePudding user response:
You can use factorize
:
df.index = df.index.factorize()[0] 1
You could also use @Chris' solution in the comments.