如何使用 pandas read_json 读取 ADSB json 数据? [复制]
Posted
技术标签:
【中文标题】如何使用 pandas read_json 读取 ADSB json 数据? [复制]【英文标题】:How can I read an ADSB json data with pandas read_json? [duplicate] 【发布时间】:2018-03-04 22:28:35 【问题描述】:我正在做:
import pandas as pd
df = pd.read_json('2016-06-20-2359Z.json')
我正在接受这个错误:
ValueError: Trailing data
这里是一个简短的 json 文件:
"src":1,"feeds":["id":1,"name":"ADSBexchange.com","polarPlot":false],"srcFeed":1,"showSil":true,"showFlg":true,"showPic":true,"flgH":20,"flgW":85,"acList":["Id":11281748,"Rcvr":1,"HasSig":false,"Icao":"AC2554","Bad":false,"Reg":"N882AS","FSeen":"\/Date(1466467166951)\/","TSecs":3,"CMsgs":1,"AltT":0,"Tisb":false,"TrkH":false,"Type":"CRJ2","Mdl":"2001 BOMBARDIER INC CL-600-2B19","Man":"Bombardier","CNum":"7503","Op":"EXPRESSJET AIRLINES INC - ATLANTA, GA","OpIcao":"ASQ","Sqk":"","VsiT":0,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":1,"Mil":false,"Cou":"United States","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":false,"SpdTyp":0,"CallSus":false,"TT":"a","Trt":1,"Year":"2001","Id":11402205,"Rcvr":1,"HasSig":true,"Sig":110,"Icao":"ADFBDD","Bad":false,"FSeen":"\/Date(1466391940977)\/","TSecs":75229,"CMsgs":35445,"Alt":8025,"GAlt":8025,"AltT":0,"Call":"TEST1234","Tisb":false,"TrkH":false,"Sqk":"0262","Help":false,"VsiT":0,"WTC":0,"Species":0,"EngType":0,"EngMount":0,"Mil":true,"Cou":"United States","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":true,"SpdTyp":0,"CallSus":false,"TT":"a","Trt":1],"totalAc":4231,"lastDv":"636019887431643594","shtTrlSec":61,"stm":1466467170029
有谁知道原因吗?
【问题讨论】:
这是json文件的一行吗? json文件是否包含多行这样的行? 对,就是json文件的一行。它就在行里面有很多 "Id":11281748,"Rcvr":1,"HasSig":false,"Icao":"AC2554","Bad":false,"Reg":"N882AS"," FSeen":"/Date(1466467166951)/","TSecs":3,"CMsgs":1,"AltT":0,"Tisb":false,"TrkH":false,"Type":"CRJ2", "Mdl":"2001 Bombardier INC CL-600-2B19","Man":"Bombardier","CNum":"7503","Op":"亚特兰大, GA","OpIcao":"ASQ"," Sqk":"","VsiT":0,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":1,"Mil":false, "Cou":"美国","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":false,"SpdTyp":0,"CallSus":false,"TT":" a","Trt":1,"年份":"2001", 如果我删除 "src":1,"feeds":["id":1,"name":"ADSBexchange.com","polarPlot":false],"srcFeed ":1,"showSil":true,"showFlg":true,"showPic":true,"flgH":20,"flgW":85,"acList": 开头和结尾,"totalAc":4231 ,"lastDv":"636019887431643594","shtTrlSec":61,"stm":1466467170029 它会找到。但是我想获得一种读取原始文件的方法,因为这样的文件太多了,我无法手动完成。 你在我下面的回答中尝试过“lines”参数吗? 【参考方案1】:如果您的 pandas 模块是最新的,请使用“lines”参数:
df = pd.read_json('2016-06-20-2359Z.json', lines=True)
【讨论】:
天啊,这行得通。我以为我确实尝试过一次,但它没有用。现在它起作用了。谢谢Alperen 抱歉,Alperen,关于同一主题,我还有另一个问题要问您。现在我所有的数据都在 df.acList 列中。如何将 df.acList 'Id', 'Rcvr'...... 放入新列? 0 ['Id': 11281748, 'Rcvr': 1, 'HasSig': False, ...名称:acList, dtype: object以上是关于如何使用 pandas read_json 读取 ADSB json 数据? [复制]的主要内容,如果未能解决你的问题,请参考以下文章
使用 pd.read_json 读取 JSON 文件时出现 ValueError 错误
如何让 pandas.read_json 将此 API 返回识别为有效的 .json?
如何在 ```pandas.read_json(...)` 期间修复 ```ValueError: Trailing data```?