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?
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}])
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?
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}])