snippetpythonCriticalCanonical
Convert list of dictionaries to a pandas DataFrame
Viewed 0 times
dataframepandasconvertlistdictionaries
Problem
How can I convert a list of dictionaries into a DataFrame?
I want to turn
into
I want to turn
[{'points': 50, 'time': '5:00', 'year': 2010},
{'points': 25, 'time': '6:00', 'month': "february"},
{'points':90, 'time': '9:00', 'month': 'january'},
{'points_h1':20, 'month': 'june'}]
into
month points points_h1 time year
0 NaN 50 NaN 5:00 2010
1 february 25 NaN 6:00 NaN
2 january 90 NaN 9:00 NaN
3 june NaN 20 NaN NaN
Solution
If
Note: this does not work with nested data.
ds is a list of dicts:df = pd.DataFrame(ds)Note: this does not work with nested data.
Code Snippets
df = pd.DataFrame(ds)Context
Stack Overflow Q#20638006, score: 1694
Revisions (0)
No revisions yet.