Skip to content
Advertisement

How to create a nested dictionary from pandas dataframe?

I have the following pandas dataframe that has thousands of rows:

JavaScript

I want to create a nested dictionary where people’s names are the keys and the dictionary of their food/drink combination is the value.

Something like this:

JavaScript

Advertisement

Answer

I solved this problem with the following code:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement