我从谷歌地图时间线得到了我的通勤报告,它是json格式。我使用这些代码:
with open('Location History.json', encoding='utf-8') as data_file:
data = json.loads(data_file.read())
pd.DataFrame(data)
数据框只有一个“位置”列。
{"locations" : [ {
"timestampMs" : "1501812184856",
"latitudeE7" : 390632197,
"longitudeE7" : -771227158,
"accuracy" : 10,
"velocity" : 1,
"heading" : 226,
"altitude" : 146,
"verticalAccuracy" : 12
}, {
"timestampMs" : "1501813902831",
"latitudeE7" : 390624516,
"longitudeE7" : -771212199,
"accuracy" : 10,
"velocity" : 5,
"heading" : 316,
"altitude" : 126,
"verticalAccuracy" : 16
},
任何建议如何将文件读入多个列,并为每个dict成员读取一行。
答案 0 :(得分:1)
从初始json中提取'location',然后转换为DataFrame
with open('Location History.json', encoding='utf-8') as data_file:
data = json.loads(data_file.read())
pd.DataFrame(data['locations'])