I have a dataframe that the first column are strings, the 2nd column are the numbers that I want to replicate each string.
df = pd.DataFrame({'String':['a','b', 'c', 'd', 'e', 'f', 'g'],
'Times':[2, 3, 5, 3, 2, 4, 5]})
df
String | Times |
---|---|
a | 2 |
b | 3 |
c | 5 |
d | 3 |
e | 2 |
f | 4 |
g | 5 |
How can I create a data frame into this in python? (stopped at d but you know the pattern). Thanks!
String | Times |
---|---|
a | 1 |
a | 2 |
b | 1 |
b | 2 |
b | 3 |
c | 1 |
c | 2 |
c | 3 |
c | 4 |
c | 5 |