Given a pd.DataFrame
such as:
print(pd.DataFrame([['a', 0, 'b'], ['c', 1, 'd'], ['f', 4, 'e']]))
0 1 2
0 a 0 b
1 c 1 d
2 f 4 e
I would like to "fill in" rows by incrementing on the integer column. That is, I would like to obtain:
0 1 2
0 a 0 b
1 c 1 d
2 NaN 2 NaN
3 NaN 3 NaN
4 f 4 e
As I am will use this within a groupby
operation in a large dataset I am looking for the most efficient code to do this.