Skip to content Skip to sidebar Skip to footer

Expand Nested List Of Dictionaries In A Pandas Dataframe Column

I have this dataframe called 'leads' I got from saving the output of an SFDC SOQL into a dataframe. I have been trying to expand column 'Leads__r.record' Company Month Amoun

Solution 1:

Try json_normalize as follows:

from pandas.io.json import json_normalize

# Convert the column of single-element lists to a list of dicts
records = [x[0] for x in df['Leads__r.record']]

# normalize the records and concat with the original df
res = pd.concat([df.drop('Leads__r.record', axis=1), json_normalize(records)], axis=1)

Post a Comment for "Expand Nested List Of Dictionaries In A Pandas Dataframe Column"