1

I want to create a hierarchical dictionary from the dataframe in the image with four columns Total--> Type--> Item-->Region. How can i do that?

The result that i want is similar to the hierarchy image below. As you can see the image has three levels (Total -- > State -- > City) but in my data set that i attach there are four levels.

Thanks

enter image description here

enter image description here

  • 1
    Refrain from showing your dataframe as an image. Your question needs a minimal reproducible example consisting of sample input, expected output, actual output, and only the relevant code necessary to reproduce the problem. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for best practices related to Pandas questions. In addition, I suggest you further explain the logic of what you are trying to accomplish – itprorh66 Oct 26 '22 at 19:59

0 Answers0