Issue
I have a dataframe that has a column with a list of dictionaries and for each dictionary I want to be able to extract the values and put them in another column as list. Please see the picture below for example which shows only 1 row of the dataframe. so for each title shown on the picture I want to extract the values and put them in a list for all the rows in a dataframe
Solution
Use ast.literal_eval
to convert the string as a list of dict then extract the `title keys from each records:
import ast
df['activities'].apply(lambda x: [d['title'] for d in ast.literal_eval(x)])
Answered By - Corralien
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.