Is it possible to fill dataframe rows based on values ​from above rows? I want to do an Excel VLOOKUP on the top rows of the dataframe

Question:

Here is a example of what i mean.

Code Name Value
1    Fred   2
2    Gary   2
1
2

I want to fill name and value by his respective code. In this case, Fred in the third row and Gary in the fourth row. Regards.

Asked By: Lucvs

||

Answers:

Try with groupby with ffill

df.update(df.groupby('Code').ffill())
df
Out[94]: 
   Code  Name  Value
0     1  Fred    2.0
1     2  Gary    2.0
2     1  Fred    2.0
3     2  Gary    2.0
Answered By: BENY
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.