简体   繁体   中英

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". 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")

I want to copy the values into a pandas data frame to save as csv or txt. How do I write/format this type of dictionary, and how do I access sets of values ie [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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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