I want to update the column Value
of the dataframe dateEANdf
with the values of the dataframe valueEANdf
but only those rows with the earlier date.
An excerpt of valueEANdf
looks as follows:
EAN-Unique Value
3324324 3.0
asd2343 2.0
Xjkhfsd 1.2
5234XAR 4.5
3434343 2.6
An excerpt of dateEANdf
looks as follows, it contains each EAN twice with an earlier and a later date.
EAN-Unique Date Start Value
3324324 2018-06-01 yes
3324324 2019-04-30 no
asd2343 2015-03-23 yes
asd2343 2015-07-11 no
Xjkhfsd 1999-04-12 yes
Xjkhfsd 2001-02-01 no
5234XAR 2000-12-13 yes
5234XAR 2013-12-13 no
3434343 1972-05-23 yes
3434343 1980-11-01 no
The updated dateEANdf
should be as follows:
EAN-Unique Date Start Value
3324324 2018-06-01 yes 3.0
3324324 2019-04-30 no
asd2343 2015-03-23 yes 2.0
asd2343 2015-07-11 no
Xjkhfsd 1999-04-12 yes 1.2
Xjkhfsd 2001-02-01 no
5234XAR 2000-12-13 yes 4.5
5234XAR 2013-12-13 no
3434343 1972-05-23 yes 2.6
3434343 1980-11-01 no
My attempt was
dateEANdf.loc[ (dateEANdf['EAN-Unique'].isin(valueEANdf.unique().tolist())) & ( dateEANdf['Start'] == 'yes') , 'Value' ] = valueEANdf['Value']
However, this puts the values "somewhere" like randomly but not to the earlier date. How to fix that?
Thanks.