从CSV内的JSON中提取数据 [英] Extract data from JSONs inside the CSV

查看:426
本文介绍了从CSV内的JSON中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆