I have this dataframe:
Month_Year City_Name Chain_Name Product_Name Product_Price
11-2021 London Aldi Pasta 2.33
11-2021 Bristol Spar Bananas 1.45
10-2021 London Tesco Olives 4.12
10-2021 Cardiff Spar Pasta 2.25
This dataframe will be displayed in nested collapsible which will expand in the following order:
Date_month:
City_Name:
Shop_name:
Product_name : Price
Theefore, I want to transform the dataframe to the following structure:
{10-2021:
{London:
{Aldi:
{Pasta:2.33}}},
{Bristol:{
{Spar:
{Bananas:1.45}}}}
Essentially I want to groupby every element recursively, starting by purchase month. The closest thing I've found is the solution in this answer, but as dictionary doesn't take duplicate values as I might have duplicate values in every column. Other than that, I am not sure if using a dictionary is the optimal answer for this problem.
My best guess is I have to use other DS type such as some type of tree, but couldn't find any way to do that.
Any advises?
{ ... "London": { "Aldi 1", "Aldi 2"} ...}