I am trying to do the following:

1 - Get the first row of Value Column of each group of person, and assign this to the rest of rows of the same group:

 Person    Job   Value
      A     1      0
      A     0      0
      A     1      1
      A     1      1
      B     1      4
      B     0      0
      B     0      0
      B     1      1

My Expected result should be:

First value of Persons A group = 0 First value of Persons A group = 4

 Person    Job   Value
      A     1      0
      A     0      0
      A     1      0
      A     1      0
      B     1      4
      B     0      4
      B     0      4
      B     1      4

I am not sure the best approach for this.

I tried this, but it`s not correct.

def first(df):
    return df.Value.iloc[0]

df['Value'] = df.groupby(Person).apply(first)

0 Answers