使用API查询,我收到了一个包含更多属性的巨大JSON响应。你知道吗
我试图以逗号分隔的CSV格式只解析响应中的某些字段。你知道吗
>>> import json
>>> resp = { "status":"success", "msg":"", "data":[ { "website":"https://www.blahblah.com", "severity":"low", "location":"unknown", "asn_number":"AS4134 Chinanet", "longitude":121.3997000000, "epoch_timestamp":1530868957, "id":"c1e15eccdd1f31395506fb85" }, { "website":"https://www.jhonedoe.co.uk/sample.pdf", "severity":"low", "location":"unknown", "asn_number":"AS4134 Chinanet", "longitude":120.1613998413, "epoch_timestamp":1530868957, "id":"933bf229e3e95a78d38223b2" } ] }
>>> response = json.loads(json.dumps(resp))
>>> KEYS = 'website', 'asn_number' , 'severity'
>>> x = []
>>> for attribute in response['data']:
csv_response = ','.join(attribute[key] for key in KEYS)
print csv_response
打印“csv\u response”时,它给出了所查询密钥的values
。你知道吗
https://www.blahblah.com,AS4134 Chinanet,low
https://www.jhonedoe.co.uk/sample.pdf,AS4134 Chinanet,low
现在,我在/tmp/
目录中有一个CSV文件。你知道吗
/tmp$cat 08_july_2018.csv
http://download2.freefiles-10.de,AS24940 Hetzner Online GmbH,high
https://www.jhonedoe.co.uk/sample.pdf,AS4134 Chinanet,low
http://download2.freefiles-11.de,AS24940 Hetzner Online GmbH,high
www.solener.com,AS20718 ARSYS INTERNET S.L.,low
https://www.blahblah.com,AS4134 Chinanet,low
www.telewizjairadio.pl,AS29522 Krakowskie e-Centrum Informatyczne JUMP Dziedzic,high
我正在尝试检查/匹配从JSON响应“csv\u response”获得的值是否存在于“/tmp/08\u july\u 2018.csv”文件中。你知道吗
从“csv_response
”值,如果任何一个行值与08_july_2018.csv
匹配,我将把条件标记为“通过”。你知道吗
关于如何将变量中的CSV值与/tmp/
目录中的文件相匹配并使条件为已传递的,有什么建议吗?你知道吗
你可以利用熊猫(下面的代码来自jupyter笔记本)。Pandas将给您很大的灵活性来匹配csv中的列。你知道吗
您需要向要读取的csvfile添加一个头文件,因此添加:
到08\u july\u 2018.csv文件
提供:
或输入所有匹配的记录,并从行中选择所需的字段:
相关问题 更多 >
编程相关推荐