I want to expand my data frame based on numeric values in a column (index_end). My df looks like this:
item | index_end |
---|---|
A | 3 |
B | 4 |
C | 1 |
I want this to expand to create rows for A from 1 to 3 and rows for B from 1 to 4 and create partitioned index.
item | index_end | index |
---|---|---|
A | 3 | 1 |
A | 3 | 2 |
A | 3 | 3 |
B | 4 | 1 |
B | 4 | 2 |
B | 4 | 3 |
B | 4 | 4 |
C | 1 | 1 |
Looking for a solution in Python/pandas. Thanks!