How to create a dataframe from this data

when i request data from an api this is the result

({'ret_code': 0, 'ret_msg': 'OK', 'ext_code': '', 'ext_info': '', 'result': [{'id': 25861171, 'symbol': 'BTCUSD', 'price': 19120, 'qty': 1, 'side': 'Sell', 'time': '2020-12-01T21:46:58.352Z'}, {'id': 25861170, 'symbol': 'BTCUSD', 'price': 19120, 'qty': 1, 'side': 'Sell', 'time': '2020-12-01T21:45:04.641Z'}, {'id': 25861169, 'symbol': 'BTCUSD', 'price': 19120, 'qty': 10, 'side': 'Sell', 'time': '2020-12-01T21:45:03.694Z'}, {'id': 25861168, 'symbol': 'BTCUSD', 'price': 19120, 'qty': 4237, 'side': 'Sell', 'time': '2020-12-01T21:44:12.092Z'}, {'id': 25861167, 'symbol': 'BTCUSD', 'price': 19120, 'qty': 58850, 'side': 'Sell', 'time': '2020-12-01T21:44:12.077Z'}, {'id': 25861166, 'symbol': 'BTCUSD', 'price': 19120, 'qty': 36190, 'side': 'Sell', 'time': '2020-12-01T21:44:04.092Z'}, {'id': 25861165, 'symbol': 'BTCUSD', 'price': 19120, 'qty': 30360, 'side': 'Sell', 'time': '2020-12-01T21:44:04.077Z'}, {'id': 25861164, 'symbol': 'BTCUSD', 'price': 19119, 'qty': 17, 'side': 'Buy', 'time': '2020-12-01T21:43:58.068Z'}, {'id': 25861163, 'symbol': 'BTCUSD', 'price': 19114.5, 'qty': 10, 'side': 'Buy', 'time': '2020-12-01T21:43:58.068Z'}, {'id': 25861162, 'symbol': 'BTCUSD', 'price': 19113.5, 'qty': 33000, 'side': 'Sell', 'time': '2020-12-01T21:43:56.092Z'}], 'time_now': '1606859227.353056'}, <bravado.requests_client.RequestsResponseAdapter object at 0x000000000E055610>)

how do i turn this into a dataframe i'm having some problem with this last part

 <bravado.requests_client.RequestsResponseAdapter object at 0x000000000E055610>)

1 answer

  • answered 2020-12-01 23:05 gray

    The data you posted looks like JSON. You can parse that into a DataFrame using Pandas.

    import pandas as pd
    df = pd.read_json(filename_or_jsonstring)
    

    You can read more about Pandas DataFrame and read_json here.

    Clearly the data you pasted is broken or incomplete. Perhaps you posted only a snippet on purpose(?). It can not start with

    'price': 19120...