1

I have the following Dataframe:

index col1
1     "a"
2
3     "b"
4
5

And from that I want to produce the following Dataframe:

index col1
1     "a"
2     "a"
3     "b"
4     "b"
5     "b"

I tried duplicating the dataframe and doing lookup, but didn't work.

gabikripka
  • 43
  • 4

1 Answers1

3

Use Series.replace for missing values and forward filling top values:

df['col1'] = df['col1'].replace('', np.nan).ffill()
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252