Skip to content
Advertisement

DataFrame from list of string dicts

So I have a list where each entry looks something like this:

JavaScript

I am trying to get a dataframe that looks like this

JavaScript

But I’m having trouble converting the format into something that can be read into a DataFrame. I know that pandas should automatically convert dicts into dataframes, but since my list elements are surrounded by quotes, it’s getting confused and giving me

JavaScript

I’ve tried using using json, concat’ing a list of dataframes, and so on, but to no avail.

Advertisement

Answer

eval is not safe. Check this comparison.

Instead use ast.literal_eval:

Assuming this to be your list:

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