简体   繁体   English

使用(?)多个键(?)访问python字典

[英]Accessing python dictionary with (?)multiple keys(?)

I have a large dictionary of values that I cannot sort.我有一个无法排序的大型值字典。 The only keys listed are "Spin_Up" and "Spin_Down".列出的唯一键是“Spin_Up”和“Spin_Down”。 These correspond to a set of listed values.这些对应于一组列出的值。 These values should have a second set of "keys" corresponding to an observation band.这些值应该具有对应于观察带的第二组“键”。 (Should have labels like "order 31") (应该有像“order 31”这样的标签)

I want to copy the values into a pandas data frame to save as csv or txt.我想将值复制到 Pandas 数据框中以另存为 csv 或 txt。 How do I write/format this type of dictionary, and how do I access sets of values ie [1,2,3]我如何编写/格式化这种类型的字典,以及如何访问值集,即 [1,2,3]

data = {"Spin_Up": [1,2,3] [4,5,6] [7,8,9],
        "Spin_Down": [10,20,30] [40,50,60] [70,80,90]}

If you make the dictionary values into a list, you can reference them based on their index in the list:如果将字典值制作成列表,则可以根据它们在列表中的索引来引用它们:

data = {"Spin_Up": [[1,2,3], [4,5,6], [7,8,9]],
        "Spin_Down": [[10,20,30], [40,50,60], [70,80,90]]}
>>> data['Spin_Down'][1] 
[40, 50, 60]

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

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