Extract dictionary value from column in data frame

You can use a list comprehension to extract feature 3 from each row in your dataframe, returning a list.

feature3 = [d.get('Feature3') for d in df.dic]

If ‘Feature3’ is not in dic, it returns None by default.

You don’t even need pandas, as you can again use a list comprehension to extract the feature from your original dictionary a.

feature3 = [d.get('Feature3') for d in a]

Leave a Comment