[英]How to split 3rd order multidimensional array into different arrays in python?
I'm making a crypto currency analysis script, the exchange api bundles the market spread in one JSON object, which prints this- 我正在制作一种加密货币分析脚本,交换api将市场价差捆绑在一个JSON对象中,该对象输出以下内容:
{'error': [], 'result': {'XXBTZEUR': {'asks': [['892.00000', '0.067',
1489866640]], 'bids': [['891.86000', '0.032', 1489866639]]}}}
As you can see, this is a multidimensional array. 如您所见,这是一个多维数组。 Let me simplify it's structure for you. 让我为您简化它的结构。
c = {'a':[],'b':{'bsubarray':{'asks':[[x1,y1,z1],[x2,y2,z2],...]
{'bids':[[x1,y1,z1],[x2,y2,z2],...]}
I'm trying to get 4 arrays out of this- ask_x
and ask_y
and bid_x
and bid_y
我正在尝试从中获取4个数组ask_x
和ask_y
以及bid_x
和bid_y
This is literally my third program in python, so any detailed explanation would really help me learn. 从字面上看,这是我在python中编写的第三个程序,因此任何详细的说明都将真正帮助我学习。
Thank you! 谢谢!
To extract ask_x
, ask_y
, etc. then you just need to zip
up the relevant asks
, etc, eg: 要提取ask_x
, ask_y
等,则只需zip
相关的asks
等,例如:
>>> c = {'a':[],'b':{'bsubarray':{'asks':[['x1','y1','z1'],['x2','y2','z2'],['x3','y3','z3']],
... 'bids':[['x1','y1','z1'],['x2','y2','z2'],['x3','y3','z3']]}}}
>>> ask_x, ask_y, ask_z = zip(*c['b']['bsubarray']['asks'])
>>> bid_x, bid_y, bid_z = zip(*c['b']['bsubarray']['bids'])
>>> ask_x
('x1', 'x2', 'x3')
>>> ask_y
('y1', 'y2', 'y3')
Using your actual data: 使用您的实际数据:
>>> c = {'error': [], 'result': {'XXBTZEUR': {'asks': [['892.00000', '0.067', 1489866640]],
... 'bids': [['891.86000', '0.032', 1489866639]]}}}
>>> ask_x, ask_y, ask_z = zip(*c['result']['XXBTZEUR']['asks'])
>>> bid_x, bid_y, bid_z = zip(*c['result']['XXBTZEUR']['bids'])
>>> ask_x
('892.00000',)
>>> ask_y
('0.067',)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.