Skip to content
Advertisement

Change structure of dictionary in Python Pandas

Is there a way of changing structure of nested dictionary? I have a column in dataframe with many rows of dictionaries, which looks like that:

JavaScript

Is there a way of modifying structure, so that it will looks like

JavaScript

without changing actual values?

Advertisement

Answer

You should read about the function apply() in pandas.

You build a function that essentially does your dictionary manipulation :

JavaScript

Then you can use apply() to call this over all the rows of your DataFrame :

JavaScript

Complete example :

JavaScript

Update for list of dictionaries :

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