mercredi 31 octobre 2018

Replace Value with another value in same column by Group

I have a dataset below:

       Date    Group  Value
 2015-02-15        A     10
 2015-02-23        A    422
 2015-03-02        A     89
 2015-02-15        B     32
 2015-02-23        B     11
 2015-02-15        C     30
 2015-03-02        C      2

I want to make a rule where, for each group, if a value appears for 2015-02-15, replace that value with the value of Date 2015-03-02 by group.

Expected output:

       Date    Group  Value
 2015-02-15        A     89    <----replaced
 2015-02-23        A    422
 2015-03-02        A     89
 2015-02-15        B     32    <----not replaced since 2015-03-02 doesn't exist
 2015-02-23        B     11
 2015-02-15        C      2    <----replaced
 2015-03-02        C      2  

Aucun commentaire:

Enregistrer un commentaire