data = [
["Item_1", "2020-06-01"],
["Item_1", "2020-06-02"],
["Item_1", "2020-05-27"],
["Item_2", "2018-04-15"],
["Item_2", "2018-04-18"],
["Item_2", "2018-04-22"],
["Item_2", "2018-04-28"],
]
df = pd.DataFrame(data, columns=["Item_ID", "Dates"])
df
I have a dataset containing a column of Item IDs and Dates. I would like to assign a "ranking" of sorts in a new column, where the rank/order value is increased IF the next date is >3 days from the previous date, otherwise it stays the same.
So the desired output would look like this:
Item_ID Dates Date Order
Item_1 2020-05-27 1
Item_1 2020-06-01 2
Item_1 2020-06-02 2
Item_2 2018-04-15 1
Item_2 2018-04-18 1
Item_2 2018-04-22 2
Item_2 2018-04-28 3