Home > other >  Is it possible to fill dataframe rows based on values ​from above rows? I want to do an Excel VLOOKU
Is it possible to fill dataframe rows based on values ​from above rows? I want to do an Excel VLOOKU

Time:09-05

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.

CodePudding user response:

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
  • Related