从CSV内的JSON中提取数据 [英] Extract data from JSONs inside the CSV
问题描述
当我在一个CSV文件中包含多个JSON时,您能否建议从JSON中提取元素的最佳方法是什么?
Could you advise what would be the best way to extract an element from JSON when I have multiple JSONs in a CSV file?
数据结构是这样的
Line1: {"CreationTime":"2018-10-29T13:40:13","Id":"35127aae-a888-4665-6514-08d63da40e14","Operation":....,"IPaddress":"x.x.x.x"...}
Line 2: {"CreationTime":"2018-10-29T13:41:13","Id":"35127aae-a888-4665-6514-08d63da40e14","Operation":....,"IPAddress":"x.x.x.x"...}
.....
LineYY:...
Line1: {"CreationTime":"2018-10-29T13:40:13","Id":"35127aae-a888-4665-6514-08d63da40e14","Operation":....,"IPaddress":"x.x.x.x"...}
Line 2: {"CreationTime":"2018-10-29T13:41:13","Id":"35127aae-a888-4665-6514-08d63da40e14","Operation":....,"IPAddress":"x.x.x.x"...}
.....
LineYY:...
我的目标是从每行(即从每个json数组)中提取IPAddress
值.最好的方法是什么?
My goal is to extract the IPAddress
value from every line, that means from every json array. What would be the best way to do it?
非常感谢!
推荐答案
您可以使用json
将每一行加载到字典中,然后访问IPAddress
You can use json
to load each line into a dictionary and then access IPAddress
import json
ips = []
for line in data.readlines():
row = json.loads(line)
ips.append(row['IPAddress'])
这篇关于从CSV内的JSON中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!