繁体   English   中英

我有一个json格式的数据文件。 如何找到并打印前 20 个 eij_max 值和相关的 Pretty_formula? 我正在使用蟒蛇

[英]I have a data file in json format. How can I find and print the top 20 eij_max values and the associated pretty_formula? I am using python

这是json格式的数据文件的一部分,包含1个条目。 我需要找到具有最高 eij_max 值的 20 个化合物 (key:pretty_formula)。 感谢您的帮助,如果这是一个基本问题,我深表歉意,我对这一切都很陌生。

{
    "num_results": 3402,
    "valid_response": true,
    "criteria": "{\"piezo\": {\"$ne\": null}}",
    "properties": "[\"pretty_formula\", \"piezo\", \"eij_max\", \"band_gap\", \"energy\"]",
    "response": [
        {
            "pretty_formula": "KMg(PO3)3",
            "piezo": {
                "eij_max": 0.09337344787836212,
                "piezoelectric_tensor": [
                    [
                        0.0,
                        0.0,
                        0.0,
                        0.0,
                        0.0,
                        0.0660250018229951
                    ],
                    [
                        0.06602500182299509,
                        -0.06602499453211871,
                        0.0,
                        0.0,
                        0.0,
                        0.0
                    ],
                    [
                        0.0,
                        0.0,
                        0.0,
                        0.0,
                        0.0,
                        0.0
                    ]
                ],
                "v_max": [
                    -0.0,
                    1.0,
                    0.0
                ]
            },
            "eij_max": null,
            "band_gap": 4.9474,
            "energy": -193.18215352
        },
        {
            "pretty_formula": "Sr2CuSi2O7",

您可以轻松地执行以下操作来访问eij_max

import json 

  
# Opening JSON file 

f = open('data.json',) 

  
# returns JSON object as  
# a dictionary 

data = json.load(f) 

  
# Iterating through the json 
# list 

for i in data['response']['piezo']['eij_max']
    print(i) 

  
# Closing file 
f.close() 

暂无
暂无

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

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