weixin_30141733
2021-04-09 21:03
采纳率: 100%
浏览 84

python小白,字典列表嵌套,取值

best_ask=data["data"][0]["ask"][0][0]

 

 

{'table': 'spot/depth5', 'data': [{'asks': [['58546.7', '0.10271386', '16'], ['58553.4', '0.00144646', '2'], ['58553.5', '0.01', '1'], ['58553.7', '0.01069735', '1'], ['58556.1', '0.02', '1']], 'bids': [['58546.6', '4.1501877', '13'], ['58542.5', '0.0005', '1'], ['58542.3', '0.00125063', '2'], ['58542.2', '0.01118886', '1'], ['58541.9', '0.06602155', '1']], 'instrument_id': 'BTC-USDT', 'timestamp': '2021-04-09T12:28:02.680Z'}]}

 

 

 

请教,为什么取不到58546.7这个值呢??

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • 已采纳

    获取的就是58546.7啊, 你比较下你的代码和下面的代码. 你写的asks 少个 s

    import pandas as pd
    import numpy as np
    
    dic = {'table': 'spot/depth5', 'data': [{'asks': [['58546.7', '0.10271386', '16'], 
                                                      ['58553.4', '0.00144646', '2'], 
                                                      ['58553.5', '0.01', '1'], 
                                                      ['58553.7', '0.01069735', '1'], 
                                                      ['58556.1', '0.02', '1']], 
                                             'bids': [['58546.6', '4.1501877', '13'],
                                                      ['58542.5', '0.0005', '1'], 
                                                      ['58542.3', '0.00125063', '2'], 
                                                      ['58542.2', '0.01118886', '1'], 
                                                      ['58541.9', '0.06602155', '1']], 
                                             'instrument_id': 'BTC-USDT', 
                                             'timestamp': '2021-04-09T12:28:02.680Z'}]}
    
    df = dic['data'][0]['asks'][0][0]    
    
    print(df)
    print(df)
    58546.7
    点赞 2 评论

相关推荐 更多相似问题