How to create a multiindex chart in Pandas that combines categories and numericals

Solution 1:

With the sample data and code you provided, you could try this:

new_df = (
    df.groupby(["week of year", "day of the week"]).sum().drop(columns=["day", "hour"])
)
new_df = new_df[new_df["units"] > 0]

So that:

print(new_df)
# Ouput
                              units
week of year day of the week       
1            Monday               2
             Tuesday              2
             Wednesday            1
2            Monday               2
             Tuesday              2
             Wednesday            1