Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to repeat row values in a column in pandas?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading