如何遍历JSON以获取小时值并写入CSV?

时间:2019-05-14 19:58:00

标签: python pandas dataframe

我有一个包含23个小时数据的JSON。 (将以相同的方式处理其他JSON,因此,其他变量位于循环的底部。)我通过lat / lng通过URL获取此数据。每个经纬度都有一个与之关联的字段<html> <head> </head> <body> <audio id="click" src="data:audio/mp3;base64,SUQzAwAAAAAAFgAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/82hQAAMoAu4AoAAAAKgCXK1AAAD/////+fKOOL///////hgTnwQKO///cXPk/4AAtASxAAAGQAAA3uMqQaQZUlUmU3Y65ndJ5vNy3f0ru8ckC8YWKEkV6dJ5Y7gl+mG27BlmS39csG5iMKANO2MNOb12M+28OKSL4IgJUg5agwsMiY47JsN9z1wVOEXUAVuaCgDSHA9VIgwIKgTJ5/9/+q2qvTAFjhQgOggTcVubuNDShuLF/vf///yzhdBJwvQ7bLUx3XWJHG6Q48LQ60AQVOfzn/////3/82hwnSYaI1+Px+AAASACXK2AAAB9Uf09TKVLtDSKu/QtEToVsnFg5YrttYGl8NzbdHgkP/z/5/4b/v/xVUMG8uTDx4AVSdRrpQQF6FHGmphrlh99GvRh+5ZLlO3dkboNehyX2P//5h///////c9cSviEDOoxMDQTtSTeNylYAENS+H0T1PpEJ5ISH9nHRqP89E1D2fvlE4zSyncppMMJP//////er95H///gAACyFEpMpJNTv/9tySSa67hNVvoIAdQz4sgPYS51Pc6dHcUyROGxOWfrTFr/82hwKhNZlWcrxDQAASACXK2AAAAMIXURJUUnRRnzZ0XJcmCaDDEpUpIyUpBzRE+ZUzEcpsSakzEvF6Y+1zQ6o3OIF4eSRrWqk/1IJ2pHy8mcZzq1mKCnW2+ivt6KqnTQdmSHsPJAxKrHTZJJFlautq93b1+o+GglUPPQECtg7xczY2/1J///4AAAkxFJk/HHVXbakkltIlnkR8knAUkdeqVZnkKPT11OZYuCKs2rDL9QsMMBVrd25Xxoi3atcSrWHFU3jRntKwmuuv/Xefn33C3quL4zrH//82hwTRah5WkbxDwCASACXK2AAAD8CJLPS2dxt1/1WLm3//+M+J399vPSk2q7o9rXFpGF6frF8Y//x//fbPveI9I0TVpWdUEqIVVSmjCYkO+rQU6y4//+cZ//+MUozxuwa+NUfv47yms775PQWFDbWhV1a0sCDXFaweKfFP//+AAA//////////////////////////4AQLAggQf/////////////////////////////////////////////////////////////////////////////////82hQVgJgAS4A4AAAAcACXOnAAAD////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/82hQ/xgAAS4AAAAAAKgCXKwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="></audio> <button onclick="snd('click')">click</button><br><br> </body> </html>

我想将每个字典中的field idvalidTime写入具有关联字段ID的value中。我应该偶然地为每个.csv获得23行。我每经度只有3小时。我的代码需要更改什么?

输入:

enter image description here

我的输出应如下所示:

enter image description here

field id
{
    "series": [{
        "validTime": "2019-05-13T02:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T03:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T04:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T05:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T06:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T07:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T08:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T09:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T10:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T11:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T12:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T13:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T14:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T15:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T16:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T17:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T18:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T19:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T20:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T21:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }, {
        "validTime": "2019-05-13T22:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.01
    }, {
        "validTime": "2019-05-13T23:00:00Z",
        "products": ["skywise-conus-1hr-precipitation-analysis"],
        "value": 0.0
    }],
    "longitude": -95.175648,
    "startTime": "2019-05-13T01:00:00Z",
    "latitude": 44.797207,
    "endTime": "2019-05-13T23:00:00Z",
    "precipitation": 0.02,
    "unit": {
        "description": "inches",
        "label": "\""
    }
}

0 个答案:

没有答案