DEV Community

Nilotpal Choudhury
Nilotpal Choudhury

Posted on

Answer: Pandas(Python) : Fill empty cells with with previous row value?

First, replace your empty cells with NaNs:

df[df[0]==""] = np.NaN

Now, Use ffill():

df.fillna(method='ffill')
#       0
#0  Text
#1    30
#2    30
#3    30
#4    31
#5  Text
#6    31
#7    31
#8    31
#9    32

Top comments (0)