我对编码非常陌生,我想将嵌套的JSON文件转换为CSV。我知道可以使用pandas模块轻松实现。
我尝试使用pandas软件包并将标准化的部分输出到cvs中。
{"status": "success", "data": {"metrics": {"mid1": {"did1": {"id": "did1", "data": [{"t": "2019-02-07T08:00:00.000Z", "v_amm": 0.32}, {"t": "2019-02-07T09:00:00.000Z", "v_amm": 0.3228888889}, {"t": "2019-02-07T10:00:00.000Z", "v_amm": 0.209375}, {"t": "2019-02-07T11:00:00.000Z", "v_amm": 0.1672}, {"t": "2019-02-07T12:00:00.000Z", "v_amm": 0.1962790698}, {"t": "2019-02-07T13:00:00.000Z", "v_amm": 0.3023529412}, {"t": "2019-02-07T14:00:00.000Z", "v_amm": 0.3298}, {"t": "2019-02-07T15:00:00.000Z", "v_amm": 0.324893617}, {"t": "2019-02-07T16:00:00.000Z", "v_amm": 0.5273469388}, {"t": "2019-02-07T17:00:00.000Z", "v_amm": 0.5739583333}, {"t": "2019-02-07T18:00:00.000Z", "v_amm": 0.5211363636}, {"t": "2019-02-07T19:00:00.000Z", "v_amm": 0.3131111111}, {"t": "2019-02-07T20:00:00.000Z", "v_amm": 0.2702173913}, {"t": "2019-02-07T21:00:00.000Z", "v_amm": 0.243877551}, {"t": "2019-02-07T22:00:00.000Z", "v_amm": 0.2474}, {"t": "2019-02-07T23:00:00.000Z", "v_amm": 0.2822222222}, {"t": "2019-02-08T00:00:00.000Z", "v_amm": 0.2879166667}, {"t": "2019-02-08T01:00:00.000Z", "v_amm": 0.3117021277}, {"t": "2019-02-08T02:00:00.000Z", "v_amm": 0.2834}, {"t": "2019-02-08T03:00:00.000Z", "v_amm": 0.2708}, {"t": "2019-02-08T04:00:00.000Z", "v_amm": 0.2275}, {"t": "2019-02-08T05:00:00.000Z", "v_amm": 0.26325}, {"t": "2019-02-08T06:00:00.000Z", "v_amm": 0.3016666667}, {"t": "2019-02-08T07:00:00.000Z", "v_amm": 0.2802702703}, {"t": "2019-02-08T08:00:00.000Z", "v_amm": 0.5284615385}, {"t": "2019-02-08T09:00:00.000Z", "v_amm": 0.4132653061}, {"t": "2019-02-08T10:00:00.000Z", "v_amm": 0.2310638298}, {"t": "2019-02-08T11:00:00.000Z", "v_amm": 0.2582978723}, {"t": "2019-02-08T12:00:00.000Z", "v_amm": 0.2257777778}, {"t": "2019-02-08T13:00:00.000Z", "v_amm": 0.23}, {"t": "2019-02-08T14:00:00.000Z", "v_amm": 0.2432}, {"t": "2019-02-08T15:00:00.000Z", "v_amm": 0.3872727273}, {"t": "2019-02-08T16:00:00.000Z", "v_amm": 0.690952381}, {"t": "2019-02-08T17:00:00.000Z", "v_amm": 0.4112820513}, {"t": "2019-02-08T18:00:00.000Z", "v_amm": 0.3334042553}, {"t": "2019-02-08T19:00:00.000Z", "v_amm": 0.3138095238}, {"t": "2019-02-08T20:00:00.000Z", "v_amm": 0.2822916667}, {"t": "2019-02-08T21:00:00.000Z", "v_amm": 0.2975510204}, {"t": "2019-02-08T22:00:00.000Z", "v_amm": 0.3173913043}, {"t": "2019-02-08T23:00:00.000Z", "v_amm": 0.2622}, {"t": "2019-02-09T00:00:00.000Z", "v_amm": 0.2725}, {"t": "2019-02-09T01:00:00.000Z", "v_amm": 0.3025}, {"t": "2019-02-09T02:00:00.000Z", "v_amm": 0.3009615385}, {"t": "2019-02-09T03:00:00.000Z", "v_amm": 0.2767391304}, {"t": "2019-02-09T04:00:00.000Z", "v_amm": 0.2729268293}, {"t": "2019-02-09T05:00:00.000Z", "v_amm": 0.2337254902}, {"t": "2019-02-09T06:00:00.000Z", "v_amm": 0.2195744681}, {"t": "2019-02-09T07:00:00.000Z", "v_amm": 0.2669565217}, {"t": "2019-02-09T08:00:00.000Z", "v_amm": 0.4612}, {"t": "2019-02-09T09:00:00.000Z", "v_amm": 0.4528}, {"t": "2019-02-09T10:00:00.000Z", "v_amm": 0.7535}, {"t": "2019-02-09T11:00:00.000Z", "v_amm": 0.6319565217}, {"t": "2019-02-09T12:00:00.000Z", "v_amm": 0.4233333333}, {"t": "2019-02-09T13:00:00.000Z", "v_amm": 0.4465306122}, {"t": "2019-02-09T14:00:00.000Z", "v_amm": 0.4646808511}, {"t": "2019-02-09T15:00:00.000Z", "v_amm": 0.9197916667}, {"t": "2019-02-09T16:00:00.000Z", "v_amm": 0.8802272727}, {"t": "2019-02-09T17:00:00.000Z", "v_amm": 0.495}, {"t": "2019-02-09T18:00:00.000Z", "v_amm": 0.5051020408}, {"t": "2019-02-09T19:00:00.000Z", "v_amm": 0.4255102041}, {"t": "2019-02-09T20:00:00.000Z", "v_amm": 0.3834090909}, {"t": "2019-02-09T21:00:00.000Z", "v_amm": 0.3304761905}, {"t": "2019-02-09T22:00:00.000Z", "v_amm": 0.3488235294}, {"t": "2019-02-09T23:00:00.000Z", "v_amm": 0.3827083333}, {"t": "2019-02-10T00:00:00.000Z", "v_amm": 0.3683333333}, {"t": "2019-02-10T01:00:00.000Z", "v_amm": 0.2956818182}, {"t": "2019-02-10T02:00:00.000Z", "v_amm": 0.2761702128}, {"t": "2019-02-10T03:00:00.000Z", "v_amm": 0.2614}, {"t": "2019-02-10T04:00:00.000Z", "v_amm": 0.2495833333}, {"t": "2019-02-10T05:00:00.000Z", "v_amm": 0.253255814}, {"t": "2019-02-10T06:00:00.000Z", "v_amm": 0.24}, {"t": "2019-02-10T07:00:00.000Z", "v_amm": 0.2276595745}, {"t": "2019-02-10T08:00:00.000Z", "v_amm": 0.6124489796}, {"t": "2019-02-10T09:00:00.000Z", "v_amm": 0.3348837209}, {"t": "2019-02-10T10:00:00.000Z", "v_amm": 0.4641176471}, {"t": "2019-02-10T11:00:00.000Z", "v_amm": 0.5104651163}, {"t": "2019-02-10T12:00:00.000Z", "v_amm": 0.6389583333}, {"t": "2019-02-10T13:00:00.000Z", "v_amm": 0.5759090909}, {"t": "2019-02-10T14:00:00.000Z", "v_amm": 0.3966666667}, {"t": "2019-02-10T15:00:00.000Z", "v_amm": 0.2819148936}, {"t": "2019-02-10T16:00:00.000Z", "v_amm": 0.4406122449}, {"t": "2019-02-10T17:00:00.000Z", "v_amm": 0.5102173913}, {"t": "2019-02-10T18:00:00.000Z", "v_amm": 0.9091489362}, {"t": "2019-02-10T19:00:00.000Z", "v_amm": 1.0484}, {"t": "2019-02-10T20:00:00.000Z", "v_amm": 0.8555319149}, {"t": "2019-02-10T21:00:00.000Z", "v_amm": 0.6444230769}, {"t": "2019-02-10T22:00:00.000Z", "v_amm": 0.5922}, {"t": "2019-02-10T23:00:00.000Z", "v_amm": 0.4859183673}, {"t": "2019-02-11T00:00:00.000Z", "v_amm": 0.4322222222}, {"t": "2019-02-11T01:00:00.000Z", "v_amm": 0.371025641}, {"t": "2019-02-11T02:00:00.000Z", "v_amm": null}, {"t": "2019-02-11T03:00:00.000Z", "v_amm": 0.25}, {"t": "2019-02-11T04:00:00.000Z", "v_amm": 0.22}, {"t": "2019-02-11T05:00:00.000Z", "v_amm": 0.1952631579}, {"t": "2019-02-11T06:00:00.000Z", "v_amm": 0.224047619}, {"t": "2019-02-11T07:00:00.000Z", "v_amm": 0.2126}, {"t": "2019-02-11T08:00:00.000Z", "v_amm": 1.3086956522}, {"t": "2019-02-11T09:00:00.000Z", "v_amm": 0.5789795918}, {"t": "2019-02-11T10:00:00.000Z", "v_amm": 0.4882608696}, {"t": "2019-02-11T11:00:00.000Z", "v_amm": 0.2674468085}, {"t": "2019-02-11T12:00:00.000Z", "v_amm": 0.4987804878}, {"t": "2019-02-11T13:00:00.000Z", "v_amm": 0.5289795918}, {"t": "2019-02-11T14:00:00.000Z", "v_amm": 0.3173469388}, {"t": "2019-02-11T15:00:00.000Z", "v_amm": 0.4991836735}, {"t": "2019-02-11T16:00:00.000Z", "v_amm": 0.2706382979}, {"t": "2019-02-11T17:00:00.000Z", "v_amm": 0.3434782609}, {"t": "2019-02-11T18:00:00.000Z", "v_amm": 0.315}, {"t": "2019-02-11T19:00:00.000Z", "v_amm": 0.2244897959}, {"t": "2019-02-11T20:00:00.000Z", "v_amm": 0.6378}, {"t": "2019-02-11T21:00:00.000Z", "v_amm": 0.487}, {"t": "2019-02-11T22:00:00.000Z", "v_amm": 0.3019565217}, {"t": "2019-02-11T23:00:00.000Z", "v_amm": 0.1968085106}, {"t": "2019-02-12T00:00:00.000Z", "v_amm": 0.1647619048}, {"t": "2019-02-12T01:00:00.000Z", "v_amm": 0.1795744681}, {"t": "2019-02-12T02:00:00.000Z", "v_amm": 0.1664444444}, {"t": "2019-02-12T03:00:00.000Z", "v_amm": 0.1862790698}, {"t": "2019-02-12T04:00:00.000Z", "v_amm": 0.1721428571}, {"t": "2019-02-12T05:00:00.000Z", "v_amm": 0.1628888889}, {"t": "2019-02-12T06:00:00.000Z", "v_amm": 0.1854166667}, {"t": "2019-02-12T07:00:00.000Z", "v_amm": 0.2134782609}, {"t": "2019-02-12T08:00:00.000Z", "v_amm": 1.1947916667}, {"t": "2019-02-12T09:00:00.000Z", "v_amm": 0.327826087}, {"t": "2019-02-12T10:00:00.000Z", "v_amm": 0.2295238095}, {"t": "2019-02-12T11:00:00.000Z", "v_amm": 0.2482}, {"t": "2019-02-12T12:00:00.000Z", "v_amm": 0.2009302326}, {"t": "2019-02-12T13:00:00.000Z", "v_amm": 0.2583333333}, {"t": "2019-02-12T14:00:00.000Z", "v_amm": 0.2688372093}, {"t": "2019-02-12T15:00:00.000Z", "v_amm": 0.2929545455}, {"t": "2019-02-12T16:00:00.000Z", "v_amm": 0.434375}, {"t": "2019-02-12T17:00:00.000Z", "v_amm": 0.3604255319}, {"t": "2019-02-12T18:00:00.000Z", "v_amm": 0.2995652174}, {"t": "2019-02-12T19:00:00.000Z", "v_amm": 0.3121276596}, {"t": "2019-02-12T20:00:00.000Z", "v_amm": 0.2925531915}, {"t": "2019-02-12T21:00:00.000Z", "v_amm": 0.2760416667}, {"t": "2019-02-12T22:00:00.000Z", "v_amm": 0.269375}, {"t": "2019-02-12T23:00:00.000Z", "v_amm": 0.2435714286}, {"t": "2019-02-13T00:00:00.000Z", "v_amm": 0.2360416667}, {"t": "2019-02-13T01:00:00.000Z", "v_amm": 0.2238095238}, {"t": "2019-02-13T02:00:00.000Z", "v_amm": 0.242}, {"t": "2019-02-13T03:00:00.000Z", "v_amm": 0.2191666667}, {"t": "2019-02-13T04:00:00.000Z", "v_amm": 0.1875555556}, {"t": "2019-02-13T05:00:00.000Z", "v_amm": 0.1870833333}, {"t": "2019-02-13T06:00:00.000Z", "v_amm": 0.1866666667}, {"t": "2019-02-13T07:00:00.000Z", "v_amm": 0.2014634146}, {"t": "2019-02-13T08:00:00.000Z", "v_amm": 0.4024489796}, {"t": "2019-02-13T09:00:00.000Z", "v_amm": 0.3254545455}, {"t": "2019-02-13T10:00:00.000Z", "v_amm": 0.2670212766}, {"t": "2019-02-13T11:00:00.000Z", "v_amm": 0.2891111111}, {"t": "2019-02-13T12:00:00.000Z", "v_amm": 0.3076086957}, {"t": "2019-02-13T13:00:00.000Z", "v_amm": 0.3214285714}, {"t": "2019-02-13T14:00:00.000Z", "v_amm": 0.3970212766}, {"t": "2019-02-13T15:00:00.000Z", "v_amm": 0.3094117647}, {"t": "2019-02-13T16:00:00.000Z", "v_amm": 0.4798039216}, {"t": "2019-02-13T17:00:00.000Z", "v_amm": 0.6639583333}, {"t": "2019-02-13T18:00:00.000Z", "v_amm": 0.3802083333}, {"t": "2019-02-13T19:00:00.000Z", "v_amm": 0.3154901961}, {"t": "2019-02-13T20:00:00.000Z", "v_amm": 0.2916326531}, {"t": "2019-02-13T21:00:00.000Z", "v_amm": 0.2527272727}, {"t": "2019-02-13T22:00:00.000Z", "v_amm": 0.3126666667}, {"t": "2019-02-13T23:00:00.000Z", "v_amm": 0.3048}, {"t": "2019-02-14T00:00:00.000Z", "v_amm": 0.3066}, {"t": "2019-02-14T01:00:00.000Z", "v_amm": 0.3171428571}, {"t": "2019-02-14T02:00:00.000Z", "v_amm": 0.2978947368}, {"t": "2019-02-14T03:00:00.000Z", "v_amm": 0.3557142857}, {"t": "2019-02-14T04:00:00.000Z", "v_amm": 0.3544897959}, {"t": "2019-02-14T05:00:00.000Z", "v_amm": 0.3187755102}, {"t": "2019-02-14T06:00:00.000Z", "v_amm": 0.2546}, {"t": "2019-02-14T07:00:00.000Z", "v_amm": 0.321}, {"t": "2019-02-14T08:00:00.000Z", "v_amm": 0.7671111111}, {"t": "2019-02-14T09:00:00.000Z", "v_amm": 0.8588}, {"t": "2019-02-14T10:00:00.000Z", "v_amm": 0.7617948718}, {"t": "2019-02-14T11:00:00.000Z", "v_amm": 0.4907843137}, {"t": "2019-02-14T12:00:00.000Z", "v_amm": 0.400212766}, {"t": "2019-02-14T13:00:00.000Z", "v_amm": 0.3742105263}, {"t": "2019-02-14T14:00:00.000Z", "v_amm": 0.4393023256}, {"t": "2019-02-14T15:00:00.000Z", "v_amm": 0.5460465116}, {"t": "2019-02-14T16:00:00.000Z", "v_amm": 0.362244898}, {"t": "2019-02-14T17:00:00.000Z", "v_amm": 0.3541860465}, {"t": "2019-02-14T18:00:00.000Z", "v_amm": 0.8687755102}, {"t": "2019-02-14T19:00:00.000Z", "v_amm": 0.6564444444}, {"t": "2019-02-14T20:00:00.000Z", "v_amm": 0.6487755102}, {"t": "2019-02-14T21:00:00.000Z", "v_amm": 0.5697368421}, {"t": "2019-02-14T22:00:00.000Z", "v_amm": 0.3656}, {"t": "2019-02-14T23:00:00.000Z", "v_amm": 0.2523913043}, {"t": "2019-02-15T00:00:00.000Z", "v_amm": 0.2346}, {"t": "2019-02-15T01:00:00.000Z", "v_amm": 0.1786363636}, {"t": "2019-02-15T02:00:00.000Z", "v_amm": 0.1639130435}, {"t": "2019-02-15T03:00:00.000Z", "v_amm": 0.2042222222}, {"t": "2019-02-15T04:00:00.000Z", "v_amm": 0.21375}, {"t": "2019-02-15T05:00:00.000Z", "v_amm": 0.1734693878}, {"t": "2019-02-15T06:00:00.000Z", "v_amm": 0.1911627907}, {"t": "2019-02-15T07:00:00.000Z", "v_amm": 0.2202040816}, {"t": "2019-02-15T08:00:00.000Z", "v_amm": 0.44}, {"t": "2019-02-15T09:00:00.000Z", "v_amm": 1.7514893617}, {"t": "2019-02-15T10:00:00.000Z", "v_amm": 0.3841666667}, {"t": "2019-02-15T11:00:00.000Z", "v_amm": 0.2727083333}, {"t": "2019-02-15T12:00:00.000Z", "v_amm": 0.4247826087}, {"t": "2019-02-15T13:00:00.000Z", "v_amm": 0.3145098039}, {"t": "2019-02-15T14:00:00.000Z", "v_amm": 0.5204}, {"t": "2019-02-15T15:00:00.000Z", "v_amm": 0.2789361702}, {"t": "2019-02-15T16:00:00.000Z", "v_amm": 0.3246}, {"t": "2019-02-15T17:00:00.000Z", "v_amm": 0.468125}, {"t": "2019-02-15T18:00:00.000Z", "v_amm": 0.2784444444}, {"t": "2019-02-15T19:00:00.000Z", "v_amm": 0.2495744681}, {"t": "2019-02-15T20:00:00.000Z", "v_amm": 0.207826087}, {"t": "2019-02-15T21:00:00.000Z", "v_amm": 0.2296078431}, {"t": "2019-02-15T22:00:00.000Z", "v_amm": 0.1797674419}, {"t": "2019-02-15T23:00:00.000Z", "v_amm": 0.1876086957}, {"t": "2019-02-16T00:00:00.000Z", "v_amm": 0.1755769231}, {"t": "2019-02-16T01:00:00.000Z", "v_amm": 0.1643181818}, {"t": "2019-02-16T02:00:00.000Z", "v_amm": 0.2426086957}, {"t": "2019-02-16T03:00:00.000Z", "v_amm": 0.3438}, {"t": "2019-02-16T04:00:00.000Z", "v_amm": 0.2142553191}, {"t": "2019-02-16T05:00:00.000Z", "v_amm": 0.1791489362}, {"t": "2019-02-16T06:00:00.000Z", "v_amm": 0.1652}, {"t": "2019-02-16T07:00:00.000Z", "v_amm": 0.1566666667}, {"t": "2019-02-16T08:00:00.000Z", "v_amm": 0.1433333333}, {"t": "2019-02-16T09:00:00.000Z", "v_amm": 0.2963043478}, {"t": "2019-02-16T10:00:00.000Z", "v_amm": 0.3028571429}, {"t": "2019-02-16T11:00:00.000Z", "v_amm": 0.3012244898}, {"t": "2019-02-16T12:00:00.000Z", "v_amm": 0.24875}, {"t": "2019-02-16T13:00:00.000Z", "v_amm": 0.26375}, {"t": "2019-02-16T14:00:00.000Z", "v_amm": 0.5273469388}, {"t": "2019-02-16T15:00:00.000Z", "v_amm": 0.4387755102}, {"t": "2019-02-16T16:00:00.000Z", "v_amm": 0.3848979592}, {"t": "2019-02-16T17:00:00.000Z", "v_amm": 0.5791666667}, {"t": "2019-02-16T18:00:00.000Z", "v_amm": 0.8112765957}, {"t": "2019-02-16T19:00:00.000Z", "v_amm": 0.8562790698}, {"t": "2019-02-16T20:00:00.000Z", "v_amm": 0.3962}, {"t": "2019-02-16T21:00:00.000Z", "v_amm": 0.3114583333}, {"t": "2019-02-16T22:00:00.000Z", "v_amm": 0.2510638298}, {"t": "2019-02-16T23:00:00.000Z", "v_amm": 0.22375}, {"t": "2019-02-17T00:00:00.000Z", "v_amm": 0.2366666667}, {"t": "2019-02-17T01:00:00.000Z", "v_amm": 0.3521428571}, {"t": "2019-02-17T02:00:00.000Z", "v_amm": 0.3085106383}, {"t": "2019-02-17T03:00:00.000Z", "v_amm": 0.259}, {"t": "2019-02-17T04:00:00.000Z", "v_amm": 0.3162222222}, {"t": "2019-02-17T05:00:00.000Z", "v_amm": 0.3095833333}, {"t": "2019-02-17T06:00:00.000Z", "v_amm": 0.2491111111}, {"t": "2019-02-17T07:00:00.000Z", "v_amm": 0.2243181818}, {"t": "2019-02-17T08:00:00.000Z", "v_amm": 0.2572916667}, {"t": "2019-02-17T09:00:00.000Z", "v_amm": 0.9667346939}, {"t": "2019-02-17T10:00:00.000Z", "v_amm": 0.6812244898}, {"t": "2019-02-17T11:00:00.000Z", "v_amm": 0.5327272727}, {"t": "2019-02-17T12:00:00.000Z", "v_amm": 0.4512244898}, {"t": "2019-02-17T13:00:00.000Z", "v_amm": 0.3831914894}, {"t": "2019-02-17T14:00:00.000Z", "v_amm": 0.7422727273}, {"t": "2019-02-17T15:00:00.000Z", "v_amm": 0.8354761905}, {"t": "2019-02-17T16:00:00.000Z", "v_amm": 0.7333333333}, {"t": "2019-02-17T17:00:00.000Z", "v_amm": 1.0157777778}, {"t": "2019-02-17T18:00:00.000Z", "v_amm": 0.9291666667}, {"t": "2019-02-17T19:00:00.000Z", "v_amm": 1.0820408163}, {"t": "2019-02-17T20:00:00.000Z", "v_amm": 0.9369230769}, {"t": "2019-02-17T21:00:00.000Z", "v_amm": 0.6525531915}]}, "did2": {"id": "did2", "data": [{"t": "2019-02-07T08:00:00.000Z", "v_alc": 0.344}, {"t": "2019-02-07T09:00:00.000Z", "v_alc": 0.3917777778}, {"t": "2019-02-07T10:00:00.000Z", "v_alc": 0.3252083333}, {"t": "2019-02-07T11:00:00.000Z", "v_alc": 0.2938}, {"t": "2019-02-07T12:00:00.000Z", "v_alc": 0.3093023256}, {"t": "2019-02-07T13:00:00.000Z", "v_alc": 0.472745098}, {"t": "2019-02-07T14:00:00.000Z", "v_alc": 0.3852}, {"t": "2019-02-07T15:00:00.000Z", "v_alc": 0.3438297872}, {"t": "2019-02-07T16:00:00.000Z", "v_alc": 0.4885714286}, {"t": "2019-02-07T17:00:00.000Z", "v_alc": 0.5139583333}, {"t": "2019-02-07T18:00:00.000Z", "v_alc": 0.4481818182}, {"t": "2019-02-07T19:00:00.000Z", "v_alc": 0.3231111111}, {"t": "2019-02-07T20:00:00.000Z", "v_alc": 0.305}, {"t": "2019-02-07T21:00:00.000Z", "v_alc": 0.3018367347}, {"t": "2019-02-07T22:00:00.000Z", "v_alc": 0.3054}, {"t": "2019-02-07T23:00:00.000Z", "v_alc": 0.326}, {"t": "2019-02-08T00:00:00.000Z", "v_alc": 0.3595833333}, {"t": "2019-02-08T01:00:00.000Z", "v_alc": 0.4104255319}, {"t": "2019-02-08T02:00:00.000Z", "v_alc": 0.3588}, {"t": "2019-02-08T03:00:00.000Z", "v_alc": 0.3382}, {"t": "2019-02-08T04:00:00.000Z", "v_alc": 0.305625}, {"t": "2019-02-08T05:00:00.000Z", "v_alc": 0.34325}, {"t": "2019-02-08T06:00:00.000Z", "v_alc": 0.3891666667}, {"t": "2019-02-08T07:00:00.000Z", "v_alc": 0.3381081081}, {"t": "2019-02-08T08:00:00.000Z", "v_alc": 0.5335897436}, {"t": "2019-02-08T09:00:00.000Z", "v_alc": 0.4008163265}, {"t": "2019-02-08T10:00:00.000Z", "v_alc": 0.3123404255}, {"t": "2019-02-08T11:00:00.000Z", "v_alc": 0.3280851064}, {"t": "2019-02-08T12:00:00.000Z", "v_alc": 0.2973333333}, {"t": "2019-02-08T13:00:00.000Z", "v_alc": 0.2947916667}, {"t": "2019-02-08T14:00:00.000Z", "v_alc": 0.3066}, {"t": "2019-02-08T15:00:00.000Z", "v_alc": 0.3938636364}, {"t": "2019-02-08T16:00:00.000Z", "v_alc": 0.5452380952}, {"t": "2019-02-08T17:00:00.000Z", "v_alc": 0.3494871795}, {"t": "2019-02-08T18:00:00.000Z", "v_alc": 0.325106383}, {"t": "2019-02-08T19:00:00.000Z", "v_alc": 0.3283333333}, {"t": "2019-02-08T20:00:00.000Z", "v_alc": 0.31375}, {"t": "2019-02-08T21:00:00.000Z", "v_alc": 0.3391836735}, {"t": "2019-02-08T22:00:00.000Z", "v_alc": 0.3617391304}, {"t": "2019-02-08T23:00:00.000Z", "v_alc": 0.3286}, {"t": "2019-02-09T00:00:00.000Z", "v_alc": 0.3425}, {"t": "2019-02-09T01:00:00.000Z", "v_alc": 0.3659090909}, {"t": "2019-02-09T02:00:00.000Z", "v_alc": 0.3580769231}, {"t": "2019-02-09T03:00:00.000Z", "v_alc": 0.3397826087}, {"t": "2019-02-09T04:00:00.000Z", "v_alc": 0.3319512195}, {"t": "2019-02-09T05:00:00.000Z", "v_alc": 0.3107843137}, {"t": "2019-02-09T06:00:00.000Z", "v_alc": 0.3089361702}, {"t": "2019-02-09T07:00:00.000Z", "v_alc": 0.3552173913}, {"t": "2019-02-09T08:00:00.000Z", "v_alc": 0.5072}, {"t": "2019-02-09T09:00:00.000Z", "v_alc": 0.4972}, {"t": "2019-02-09T10:00:00.000Z", "v_alc": 0.64175}, {"t": "2019-02-09T11:00:00.000Z", "v_alc": 0.4969565217}, {"t": "2019-02-09T12:00:00.000Z", "v_alc": 0.3991666667}, {"t": "2019-02-09T13:00:00.000Z", "v_alc": 0.4159183673}, {"t": "2019-02-09T14:00:00.000Z", "v_alc": 0.4604255319}, {"t": "2019-02-09T15:00:00.000Z", "v_alc": 0.6008333333}, {"t": "2019-02-09T16:00:00.000Z", "v_alc": 0.5222727273}, {"t": "2019-02-09T17:00:00.000Z", "v_alc": 0.3736956522}, {"t": "2019-02-09T18:00:00.000Z", "v_alc": 0.3779591837}, {"t": "2019-02-09T19:00:00.000Z", "v_alc": 0.3551020408}, {"t": "2019-02-09T20:00:00.000Z", "v_alc": 0.3625}, {"t": "2019-02-09T21:00:00.000Z", "v_alc": 0.3319047619}, {"t": "2019-02-09T22:00:00.000Z", "v_alc": 0.3476470588}, {"t": "2019-02-09T23:00:00.000Z", "v_alc": 0.3747916667}, {"t": "2019-02-10T00:00:00.000Z", "v_alc": 0.3697916667}, {"t": "2019-02-10T01:00:00.000Z", "v_alc": 0.3229545455}, {"t": "2019-02-10T02:00:00.000Z", "v_alc": 0.3221276596}, {"t": "2019-02-10T03:00:00.000Z", "v_alc": 0.3158}, {"t": "2019-02-10T04:00:00.000Z", "v_alc": 0.32125}, {"t": "2019-02-10T05:00:00.000Z", "v_alc": 0.3241860465}, {"t": "2019-02-10T06:00:00.000Z", "v_alc": 0.303125}, {"t": "2019-02-10T07:00:00.000Z", "v_alc": 0.3140425532}, {"t": "2019-02-10T08:00:00.000Z", "v_alc": 0.5367346939}, {"t": "2019-02-10T09:00:00.000Z", "v_alc": 0.3625581395}, {"t": "2019-02-10T10:00:00.000Z", "v_alc": 0.4341176471}, {"t": "2019-02-10T11:00:00.000Z", "v_alc": 0.411627907}, {"t": "2019-02-10T12:00:00.000Z", "v_alc": 0.466875}, {"t": "2019-02-10T13:00:00.000Z", "v_alc": 0.4318181818}, {"t": "2019-02-10T14:00:00.000Z", "v_alc": 0.3642222222}, {"t": "2019-02-10T15:00:00.000Z", "v_alc": 0.3268085106}, {"t": "2019-02-10T16:00:00.000Z", "v_alc": 0.393877551}, {"t": "2019-02-10T17:00:00.000Z", "v_alc": 0.4158695652}, {"t": "2019-02-10T18:00:00.000Z", "v_alc": 0.5480851064}, {"t": "2019-02-10T19:00:00.000Z", "v_alc": 0.5466}, {"t": "2019-02-10T20:00:00.000Z", "v_alc": 0.4887234043}, {"t": "2019-02-10T21:00:00.000Z", "v_alc": 0.4388461538}, {"t": "2019-02-10T22:00:00.000Z", "v_alc": 0.4172}, {"t": "2019-02-10T23:00:00.000Z", "v_alc": 0.3665306122}, {"t": "2019-02-11T00:00:00.000Z", "v_alc": 0.3511111111}, {"t": "2019-02-11T01:00:00.000Z", "v_alc": 0.3243589744}, {"t": "2019-02-11T02:00:00.000Z", "v_alc": null}
这是我尝试过的。我不确定如何更深入地了解嵌套标头。
import pandas as pd
from pandas.io.json import json_normalize
import json
with open('AQ_T1_Feb19.json') as file:
data = json.load(file)
df = json_normalize(data, ['status'],['data'])
df.to_csv('AQ_T1_Feb19.csv', encoding='utf-8', index=False)
csv文件应将t和v_amm作为标题,并在列中包含相应的值。我无法上传图片,但希望您能理解我的意思。
答案 0 :(得分:1)
json_normalize
:record_path
keys
{'data': {'metrics': {'mid1': {'did1': {'data': [{'t': <class 'str'>,
'v_amm': <class 'float'>}]},
'did2': {'data': [{'t': <class 'str'>,
'v_alc': <class 'float'>}]}}}}}
null
值,必须替换为None
from pandas.io.json import json_normalize
import pandas as pd
data = {your json}
df_v_alc = json_normalize(data, ['data', 'metrics', 'mid1', 'did2', 'data'])
t v_alc
2019-02-07T08:00:00.000Z 0.344000
2019-02-07T09:00:00.000Z 0.391778
2019-02-07T10:00:00.000Z 0.325208
2019-02-07T11:00:00.000Z 0.293800
2019-02-07T12:00:00.000Z 0.309302
df_v_amm = json_normalize(data, ['data', 'metrics', 'mid1', 'did1', 'data'])
t v_amm
2019-02-07T08:00:00.000Z 0.320000
2019-02-07T09:00:00.000Z 0.322889
2019-02-07T10:00:00.000Z 0.209375
2019-02-07T11:00:00.000Z 0.167200
2019-02-07T12:00:00.000Z 0.196279
答案 1 :(得分:0)
nested-csv
https://github.com/kawasin73/nested_csv
$ pip3 install nested-csv
正在转换python脚本。
import json
import nested_csv
with open("sample.json") as f:
data = json.loads(f.read())
fieldnames = nested_csv.generate_fieldnames(data)
with open("sample.csv", "w+") as f:
w = nested_csv.NestedDictWriter(f, fieldnames)
w.writeheader()
w.writerow(data)
with open("did1.csv", "w+") as f:
fieldnames = ["data.metrics.mid1.did1.data[id]", "data.metrics.mid1.did1.data[].t",
"data.metrics.mid1.did1.data[].v_amm", "data.metrics.mid1.did1.id", "status"]
w = nested_csv.NestedDictWriter(f, fieldnames)
w.writeheader()
w.writerow(data)
with open("did2.csv", "w+") as f:
fieldnames = ["data.metrics.mid1.did2.data[id]", "data.metrics.mid1.did2.data[].t",
"data.metrics.mid1.did2.data[].v_alc", "data.metrics.mid1.did2.id", "status"]
w = nested_csv.NestedDictWriter(f, fieldnames)
w.writeheader()
w.writerow(data)
您可以获取以下csv文件。
data.metrics.mid1.did1.data[id],data.metrics.mid1.did1.data[].t,data.metrics.mid1.did1.data[].v_amm,data.metrics.mid1.did1.id,data.metrics.mid1.did2.data[id],data.metrics.mid1.did2.data[].t,data.metrics.mid1.did2.data[].v_alc,data.metrics.mid1.did2.id,status
0,2019-02-07T08:00:00.000Z,0.32,did1,0,2019-02-07T08:00:00.000Z,0.344,did2,success
1,2019-02-07T09:00:00.000Z,0.3228888889,did1,1,2019-02-07T09:00:00.000Z,0.3917777778,did2,success
2,2019-02-07T10:00:00.000Z,0.209375,did1,2,2019-02-07T10:00:00.000Z,0.3252083333,did2,success
3,2019-02-07T11:00:00.000Z,0.1672,did1,3,2019-02-07T11:00:00.000Z,0.2938,did2,success
4,2019-02-07T12:00:00.000Z,0.1962790698,did1,4,2019-02-07T12:00:00.000Z,0.3093023256,did2,success
5,2019-02-07T13:00:00.000Z,0.3023529412,did1,5,2019-02-07T13:00:00.000Z,0.472745098,did2,success
6,2019-02-07T14:00:00.000Z,0.3298,did1,6,2019-02-07T14:00:00.000Z,0.3852,did2,success
data.metrics.mid1.did1.data[id],data.metrics.mid1.did1.data[].t,data.metrics.mid1.did1.data[].v_amm,data.metrics.mid1.did1.id,status
0,2019-02-07T08:00:00.000Z,0.32,did1,success
1,2019-02-07T09:00:00.000Z,0.3228888889,did1,success
2,2019-02-07T10:00:00.000Z,0.209375,did1,success
3,2019-02-07T11:00:00.000Z,0.1672,did1,success
4,2019-02-07T12:00:00.000Z,0.1962790698,did1,success
5,2019-02-07T13:00:00.000Z,0.3023529412,did1,success
6,2019-02-07T14:00:00.000Z,0.3298,did1,success
data.metrics.mid1.did2.data[id],data.metrics.mid1.did2.data[].t,data.metrics.mid1.did2.data[].v_alc,data.metrics.mid1.did2.id,status
0,2019-02-07T08:00:00.000Z,0.344,did2,success
1,2019-02-07T09:00:00.000Z,0.3917777778,did2,success
2,2019-02-07T10:00:00.000Z,0.3252083333,did2,success
3,2019-02-07T11:00:00.000Z,0.2938,did2,success
4,2019-02-07T12:00:00.000Z,0.3093023256,did2,success
5,2019-02-07T13:00:00.000Z,0.472745098,did2,success
6,2019-02-07T14:00:00.000Z,0.3852,did2,success