简体   繁体   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

Here is part of the data file in json format, containing 1 entry.这是json格式的数据文件的一部分,包含1个条目。 I need to find the 20 compounds (key:pretty_formula) with the highest eij_max values.我需要找到具有最高 eij_max 值的 20 个化合物 (key:pretty_formula)。 I appreciate the help, I apologise if this is a basic question, I am new to all this.感谢您的帮助,如果这是一个基本问题,我深表歉意,我对这一切都很陌生。

{
    "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",

You can easily do something like this to access the eij_max :您可以轻松地执行以下操作来访问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.

相关问题 尝试以 json 格式对我的数据进行分析。 到目前为止,我的代码下面我的问题是如何加入我的所有数据,请帮助我是 Python 新手 - trying do analysis to my data in json format. my code below so far my questions is how can I join all my data , pls help I am new to python 如何使用 python 中的 json 文件制作漂亮的 dataframe? - How can I make pretty dataframe using json file in python? 我正在尝试使用 Pandas 将 json 文件转为特定格式。 我想在某些列上旋转它 - I am trying to pivot a json file using pandas to be in a specific format. I want to pivot it on certain columns Python:如何迭代 20 列并找到顶列? - Python: How can I iterate 20 columns and find the top column? 我有一些文件格式的数据。 我想知道每一行的第一个字符串是什么,并计算它们重复了多少次 - I have some data in a file format. I want to know what is the first string in each line and count how many times they are repeated 我无法从 python 中的 JSON 数据中找到属性值 - I am unable to find attribute values from JSON data in python 如何存储和打印前20%的功能名称和分数? - How can I store and print the top 20% feature names and scores? 我正在制作 python web 应用程序。 需要帮助了解如何托管、格式化。 呈现它 - I am making a python web app. Need help understanding how to host, format. present it 我怎么会打印python文档字符串? - How would I pretty print a python docstring? Python:我的结果正确,但格式错误。 用弦练习。 知道如何解决吗? - Python: I have right result but in wrong format. Practicing with strings. Any idea how to fix it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM