熊猫库访问大JSON数据问题

时间:2020-07-25 15:33:30

标签: json python-3.x pandas

import pandas as pd
import json
import math

f = open('./report.json',)

data = json.load(f)

df = pd.DataFrame(data['dependencies'])
lst = []

for i in range(len(df)):
    x = ((df.iloc[[i]]['vulnerabilities']).iloc[0])
    if not (isinstance(x, float) and math.isnan(x)):
          print(x)

此函数的输出为列表:

[{'source': 'NVD', 'name': 'CVE-2017-16116', 'severity': 'HIGH', 'cvssv2': {'score': 5.0, 'accessVector': 'NETWORK', 'accessComplexity': 'LOW', 'authenticationr': 'NONE', 'confidentialImpact': 'NONE', 'integrityImpact': 'NONE', 'availabilityImpact': 'PARTIAL', 'severity': 'MEDIUM'}, 'cvssv3': {'baseScore': 7.5, 'attackVector': 'NETWORK', 'attackComplexity': 'LOW', 'privilegesRequired': 'NONE', 'userInteraction': 'NONE', 'scope': 'UNCHANGED', 'confidentialityImpact': 'NONE', 'integrityImpact': 'NONE', 'availabilityImpact': 'HIGH', 'baseSeverity': 'HIGH'}, 'cwes': ['CWE-400'], 'description':]]]

您可以看到“严重性”列。现在,我正在尝试列出所有具有较高优先级的“严重性”数据。但是出现这样的错误:

TypeError:列表索引必须是整数或切片,而不是str

请任何人能进一步帮助我...

0 个答案:

没有答案