Use of cumcount() +1 to define the last weeks of a dataframe

Viewed 15

I am having some trouble to achieve the output below : Final output that i want

Instead by using the cumcount()+1 function this way :

week_row_number = model_week_part_shift_hub[
    ["date_run", "week_number", "is_weekend", "shift", "depot_id", "product_id"]
].drop_duplicates()
week_row_number["row_number"] = (
    week_row_number.sort_values(["week_number"], ascending=False)
    .groupby(["date_run","is_weekend","week_number", "shift", "depot_id", "product_id"])
    .cumcount()
    + 1

And here is my output :

Real output

Any idea on how to solve the issue ? Thanks in advance

0 Answers
Related