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

How do I drag cell values to other lines until a certain limit in python?

There is a dataframe which a few lines has values and the followings lines are NaN filled. The number of NaN rows can varry and I need to drag the first row value to the following until the next filled row. Please find the example below.

Also there is a delimited line (‘—-‘) between different names.

Name ID
John 0123
NaN 0127
NaN 0163
--------
Bill 0122
NaN 0194
NaN 0125
NaN 0555
NaN 0666

What I want:

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

Name ID
John 0123
John 0127
John 0163
--------
Bill 0122
Bill  0194
Bill  0125
Bill  0555
Bill  0666

>Solution :

Just use df['Name'].fillna(method='ffill', inplace=True)

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