简体   繁体   English

将 API 响应转换为 Python Pandas 数据帧

[英]Converting an API response into Python Pandas Data Frame

Dear community experts尊敬的社区专家

I have an API returning the following structure that I need to convert into a pandas data frame.我有一个 API 返回以下结构,我需要将其转换为 pandas 数据帧。 How could I do to create such Data Frame?.我该怎么做才能创建这样的数据框?

Thanks, Hernan谢谢, 埃尔南

[{'quoteSymbol': 'USDT',
  'baseSymbol': 'ETH',
  'orderBooks': [{'exchange': 'Bittrex',
    'orderBook': {'asks': [{'price': '2112.20173745',
       'quantity': '1.41879654'},
      {'price': '2112.38300246', 'quantity': '1.41868464'},
      {'price': '2112.56760000', 'quantity': '0.00209173'}],
     'bids': [{'price': '2111.08708148', 'quantity': '1.41874566'},
      {'price': '2110.87591399', 'quantity': '1.41874566'},
      {'price': '2110.73500000', 'quantity': '2.35200000'}]}},
   {'exchange': 'Binance',
    'orderBook': {'asks': [{'price': '2092.91000000',
       'quantity': '27.01387000'},
      {'price': '2092.96000000', 'quantity': '3.34463000'},
      {'price': '2092.97000000', 'quantity': '8.13200000'}],
     'bids': [{'price': '2112.52000000', 'quantity': '1.45438000'},
      {'price': '2112.36000000', 'quantity': '0.45074000'},
      {'price': '2112.35000000', 'quantity': '0.97545000'}]}},
   {'exchange': 'Bitstamp', 'orderBook': None}]}

My suggestion is to first transform the JSON you have into a list of dictionaries.我的建议是首先将您拥有的 JSON 转换为字典列表。 Each dictionary should have keys that correspond to the columns you want in the final dataframe.每个字典都应具有与最终 dataframe 中所需的列相对应的键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM