使用Pandas解析JSON-功能和错误之间的区别不清楚

时间:2019-05-09 22:47:51

标签: json pandas parsing geojson

我可以解析此JSON:

r='''[{"count":3,"date_time":"2014-08-26T00:00:00","quality_code":0,"value":30},{"count":67,"date_time":"2014-08-27T00:00:00","quality_code":0,"value":32.388059701492537},{"count":72,"date_time":"2014-08-28T00:00:00","quality_code":0,"value":48.888888888888886},{"count":72,"date_time":"2014-08-29T00:00:00","quality_code":0,"value":72.083333333333329},{"count":69,"date_time":"2014-08-30T00:00:00","quality_code":0,"value":86.376811594202906},{"count":72,"date_time":"2014-08-31T00:00:00","quality_code":0,"value":85.833333333333329},{"count":72,"date_time":"2014-09-01T00:00:00","quality_code":0,"value":88.194444444444443},{"count":69,"date_time":"2014-09-02T00:00:00","quality_code":0,"value":93.623188405797094},{"count":72,"date_time":"2014-09-03T00:00:00","quality_code":0,"value":114.58333333333333},{"count":72,"date_time":"2014-09-04T00:00:00","quality_code":0,"value":113.75},{"count":69,"date_time":"2014-09-05T00:00:00","quality_code":0,"value":119.85507246376811},{"count":60,"date_time":"2014-09-06T00:00:00","quality_code":0,"value":129.5},{"count":72,"date_time":"2014-09-07T00:00:00","quality_code":0,"value":129.72222222222223},{"count":66,"date_time":"2014-09-08T00:00:00","quality_code":0,"value":134.09090909090909},{"count":72,"date_time":"2014-09-09T00:00:00","quality_code":0,"value":131.52777777777777},{"count":72,"date_time":"2014-09-10T00:00:00","quality_code":0,"value":145},{"count":72,"date_time":"2014-09-11T00:00:00","quality_code":0,"value":160},{"count":72,"date_time":"2014-09-12T00:00:00","quality_code":0,"value":164.44444444444446},{"count":72,"date_time":"2014-09-13T00:00:00","quality_code":0,"value":185.55555555555554}]'''

但不是貌似相同的结构。我在这里想念的有什么区别?!

r2='''[{"count":46,"date_time":"2012-04-02T00:00:00","quality_code":2147486339,"value":26.663043478259734},{"count":93,"date_time":"2012-04-03T00:00:00","quality_code":0,"value":22.420430107526887},{"count":65,"date_time":"2012-04-04T00:00:00","quality_code":2147486339,"value":22.677692307695175},{"count":15,"date_time":"2012-04-09T00:00:00","quality_code":0,"value":5.4066666666666663},{"count":96,"date_time":"2012-04-10T00:00:00","quality_code":0,"value":.54791666666666661},{"count":96,"date_time":"2012-04-11T00:00:00","quality_code":0,"value":2.1635416666666671},{"count":65,"date_time":"2012-04-12T00:00:00","quality_code":0,"value":1.3661538461538452},{"count":69,"date_time":"2012-04-19T00:00:00","quality_code":0,"value":-1.5202898550724639},{"count":96,"date_time":"2012-04-20T00:00:00","quality_code":0,"value":-1.4604166666666665},{"count":96,"date_time":"2012-04-21T00:00:00","quality_code":0,"value":-3.1281250000000007},{"count":96,"date_time":"2012-04-22T00:00:00","quality_code":0,"value":-3.9416666666666669},{"count":96,"date_time":"2012-04-23T00:00:00","quality_code":0,"value":-3.6156249999999992},{"count":96,"date_time":"2012-04-24T00:00:00","quality_code":0,"value":-3.4593749999999979},{"count":96,"date_time":"2012-04-25T00:00:00","quality_code":0,"value":-2.863541666666666},{"count":96,"date_time":"2012-04-26T00:00:00","quality_code":0,"value":-3.4468749999999999},{"count":96,"date_time":"2012-04-27T00:00:00","quality_code":0,"value":-2.4354166666666668},{"count":96,"date_time":"2012-04-28T00:00:00","quality_code":0,"value":-4.0239583333333337},{"count":96,"date_time":"2012-04-29T00:00:00","quality_code":0,"value":-3.8885416666666655},{"count":89,"date_time":"2012-04-30T00:00:00","quality_code":0,"value":-3.4741573033707871},{"count":79,"date_time":"2012-05-01T00:00:00","quality_code":0,"value":-7.2860759493670892},{"count":96,"date_time":"2012-05-02T00:00:00","quality_code":0,"value":-12.240625},{"count":96,"date_time":"2012-05-03T00:00:00","quality_code":0,"value":-9.6708333333333361},{"count":88,"date_time":"2012-05-04T00:00:00","quality_code":0,"value":-5.8784090909090905},{"count":96,"date_time":"2012-05-05T00:00:00","quality_code":0,"value":-5.6479166666666698}]'''

通过以下方式与熊猫进行解析

dat=pd.read_json(r)

两个原始JSON字符串都从API查询返回到同一数据库,只是请求了不同的变量。

1 个答案:

答案 0 :(得分:0)

JSON解析器阻塞了没有前导零的十进制值。

修复了python字符串操作:

r= r.replace('''"value:".''', '''"value:"0.''')