我正在使用来自ACN Data的JSON文件进行EV Charging行为。我想用python读取它并将其转换为pandas框架。问题是JSON有多个对象,我面临着一些困难,难以将所有数据汇总,包括userInputs,在表行中。
下面的JSON:
{
"_meta":
{
"end": "Sat, 01 Jan 2022 08:00:00 GMT",
"min_kWh": null,
"site": "caltech",
"start": "Mon, 01 Jan 2018 08:00:00 GMT"
},
"_items": [
{
"_id": "5bc90cb9f9af8b0d7fe77cd2",
"clusterID": "0039",
"connectionTime": "Wed, 25 Apr 2018 11:08:04 GMT",
"disconnectTime": "Wed, 25 Apr 2018 13:20:10 GMT",
"doneChargingTime": "Wed, 25 Apr 2018 13:21:10 GMT",
"kWhDelivered": 7.932,
"sessionID": "2_39_78_362_2018-04-25 11:08:04.400812",
"siteID": "0002",
"spaceID": "CA-496",
"stationID": "2-39-78-362",
"timezone": "America/Los_Angeles",
"userID": null,
"userInputs": null
},
{
"_id": "5ca2ad12f9af8b68e0cb5d47",
"clusterID": "0039",
"connectionTime": "Sat, 16 Mar 2019 14:39:41 GMT",
"disconnectTime": "Sat, 16 Mar 2019 18:39:04 GMT",
"doneChargingTime": "Sat, 16 Mar 2019 18:25:28 GMT",
"kWhDelivered": 24.804,
"sessionID": "2_39_124_22_2019-03-16 14:39:40.648349",
"siteID": "0002",
"spaceID": "CA-312",
"stationID": "2-39-124-22",
"timezone": "America/Los_Angeles",
"userID": "000001039",
"userInputs": [
{
"WhPerMile": 271,
"kWhRequested": 65.04,
"milesRequested": 240,
"minutesAvailable": 203,
"modifiedAt": "Sat, 16 Mar 2019 14:40:30 GMT",
"paymentRequired": true,
"requestedDeparture": "Sat, 16 Mar 2019 18:02:41 GMT",
"userID": 1039
}
]
}
]}
字符串
我试过只阅读“_items”,它起作用了。但是我仍然不能用所有用户输入的数据创建一行。
Python代码如下:
import json
import pandas as pd
data = json.load(open("content.json"))
acn_ev_set_json = pd.DataFrame(data)
acn_ev_set_json.tail(3)
型
用户输入如下所示:
Some links that helped me:数据集:https://ev.caltech.edu/dataset文章数据集:https://ev.caltech.edu/assets/pub/ACN_Data_Analysis_and_Applications.pdf stackoverflow问题:Read JSON to pandas dataframe - ValueError: Mixing dicts with non-Series may lead to ambiguous ordering
1条答案
按热度按时间a14dhokn1#
试试这个:
字符串