I have a list that contains nested json data and I would like to convert everything that is in the ‘data:’ tag into a data frame. The list contains multiple records inside the
emptylist = [{'data': {'id': 7478290440, 'version': 0, 'bonus_opening_balance': 7.4, 'cash_opening_balance': 30.83, 'external_round_id': '8997958938', 'game_id': 29788, 'game_session_id': 144418070, 'last_updated_at': '2023-06-29T14:03:03Z', 'started_at': '2023-06-29T14:03:03Z', 'status': 0, 'cash_stake': 0, 'cash_win': 0, 'bonus_stake': 0, 'bonus_win': 0}, 'metadata': {'timestamp': '2023-06-29T12:03:07.699650Z', 'record-type': 'data', 'operation': 'insert', 'partition-key-type': 'schema-table', 'schema-name': 'revolve', 'table-name': 'game_round', 'transaction-id': 103414267563647}}, {'data': {'id': 7478290359, 'version': 2, 'bonus_opening_balance': 0, 'cash_opening_balance': 11.13, 'ended_at': '2023-06-29T14:03:03Z', 'external_round_id': '8997958480', 'game_id': 16210, 'game_session_id': 144418025, 'last_updated_at': '2023-06-29T14:03:03Z', 'started_at': '2023-06-29T14:02:58Z', 'status': 1, 'cash_stake': 0.2, 'cash_win': 0.03, 'bonus_stake': 0, 'bonus_win': 0}, 'metadata': {'timestamp': '2023-06-29T12:03:07.708711Z', 'record-type': 'data', 'operation': 'update', 'partition-key-type': 'schema-table', 'schema-name': 'revolve', 'table-name': 'game_round', 'transaction-id': 103414267564722}}, {'data': {'id': 7478290440, 'version': 1, 'bonus_opening_balance': 7.4, 'cash_opening_balance': 30.83, 'external_round_id': '8997958938', 'game_id': 29788, 'game_session_id': 144418070, 'last_updated_at': '2023-06-29T14:03:03Z', 'started_at': '2023-06-29T14:03:03Z', 'status': 0, 'cash_stake': 0.2, 'cash_win': 0, 'bonus_stake': 0, 'bonus_win': 0}, 'metadata': {'timestamp': '2023-06-29T12:03:07.717096Z', 'record-type': 'data', 'operation': 'update', 'partition-key-type': 'schema-table', 'schema-name': 'revolve', 'table-name': 'game_round', 'transaction-id': 103414267565254}}]
print(emptylist)
2
Answers
Try this
You could create a DataFrame from the list and use
apply
on the"data"
series to make it a DataFrame: