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

Question:

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:

Name ID
John 0123
John 0127
John 0163
--------
Bill 0122
Bill  0194
Bill  0125
Bill  0555
Bill  0666
Asked By: Thiago Santos

||

Answers:

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

Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.