0

My column looks like this:

XXXXXXXX
     NaN
     NaN
     NaN
YYYYYYYY
     NaN
     NaN
     NaN

Instead of NaN i want to repeat row value untill next value and so on.

XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
YYYYYYYY
YYYYYYYY
YYYYYYYY
YYYYYYYY
alcheringa
  • 33
  • 3
  • There are 2 directions you could go with this: change the way you create the dataframe or use other columns to populate. Could you post more information about how you created the dataframe or about other columns (in particular do all 'X' columns have another column in common?) – Tristan Reid Feb 19 '22 at 14:40

1 Answers1

1
df[column].fillna(method="ffill")

Check out the explanation and examples of available methods ({‘backfill’, ‘bfill’, ‘pad’, ‘ffill’, None}) from the doc https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.fillna.html

Raymond Kwok
  • 2,461
  • 2
  • 9
  • 11