Converting a list into a pandas dataframe using keys as column names

Question:

I have a list in the following format:

[{'date': '2019-05-06', 'open': 51.0725, 'high': 52.21, 'low': 50.875, 'close': 52.12, 'volume': 129772452}, 
 {'date': '2019-05-07', 'open': 51.47, 'high': 51.854375, 'low': 50.20625, 'close': 50.715, 'volume': 155054790}, 
 {'date': '2019-05-08', 'open': 50.475, 'high': 51.335, 'low': 50.4375, 'close': 50.725, 'volume': 105358016}, 
 {'date': '2019-05-09', 'open': 50.1, 'high': 50.42, 'low': 49.165, 'close': 50.18, 'volume': 139634430}]

How do I store this list as a pandas dataframe with the keys (‘date’,’open’,’high’,’low’,’close’,’volume’) as the column names and the values as records in the dataframe?

Asked By: siralbert

||

Answers:

pd.DataFrame([{'date': '2019-05-06', 'open': 51.0725, 'high': 52.21, 'low': 50.875, 'close': 52.12, 'volume': 129772452}, 
 {'date': '2019-05-07', 'open': 51.47, 'high': 51.854375, 'low': 50.20625, 'close': 50.715, 'volume': 155054790}, 
 {'date': '2019-05-08', 'open': 50.475, 'high': 51.335, 'low': 50.4375, 'close': 50.725, 'volume': 105358016}, 
 {'date': '2019-05-09', 'open': 50.1, 'high': 50.42, 'low': 49.165, 'close': 50.18, 'volume': 139634430}])

Output

Answered By: Jason Katz
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.