My dataframe df
contains products which have an EAN, an earlier and later date, 'yes' and 'no' labels and values.
EAN-Unique Date Start Value
3324324 2019-04-30 no 0.11
3324324 2018-06-01 yes 56.03
asd2343 2015-03-23 yes 8.02
asd2343 2015-07-11 no 8.45
Xjkhfsd 1999-04-12 yes 12.33
Xjkhfsd 2001-02-01 no 9.11
5234XAR 2013-12-13 no 15.75
5234XAR 2000-12-13 yes 9.00
3434343 1972-05-23 yes 1.26
3434343 1980-11-01 no 2.77
I want to sort the groups of EAN-Uniques (for example 3324324 is a group, asd2343 is a group and so on) based on
- lowest to highest value based on the earlier date and
- within each group from earlier date to later date.
The df
shall look as follows:
EAN-Unique Date Start Value
3434343 1972-05-23 yes 1.26
3434343 1980-11-01 no 2.77
asd2343 2015-03-23 yes 8.02
asd2343 2015-07-11 no 8.45
5234XAR 2000-12-13 yes 9.00
5234XAR 2013-12-13 no 15.75
Xjkhfsd 1999-04-12 yes 12.33
Xjkhfsd 2001-02-01 no 9.11
3324324 2018-06-01 yes 56.03
3324324 2019-04-30 no 0.11
My attempt was to sort it
df = df.sort_values(by=['EAN-Unique','Date','Value'], ascending=[True,True,True]).reset_index(drop=True)
But it didn't work as intended. Can anybody help me out?
Thanks!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…