![](/img/trans.png)
[英]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
[英]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.