我从我的数据库中导出了原始数据集,它是一个嵌套的json结构。因此,基于此,我想将这种数据集转换成熊猫数据帧,但是,我不知道如何将这种结构转换成我想要的数据帧。你知道吗
我已经练习了一些关于使用json\u normalize处理kaggle中的嵌套json数据结构的教程,但是在我的例子中,我无法将json结构实现为我想要的dataframe。你知道吗
我想要实现的数据帧是这样的
下面是我导出的嵌套json结构
[
{
"tripId" : "19062521016",
"driveDisstance" : 0,
"devicetime" : "2019-06-26 06:02:30",
"speeds" : "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,1,2,4,11,13,13,14,14,14,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"locations" : "[{\"latitude\":0,\"longitude\":0},{\"latitude\":0,\"longitude\":0},{\"latitude\":0,\"longitude\":0},{\"latitude\":0,\"longitude\":0},{\"latitude\":0,\"longitude\":0},{\"latitude\":0,\"longitude\":0}]",
"dangerousValues" : "[{\"quickTick\":0},{\"quicRatio\":1023},{\"quicCount\":0},{\"brakeTick\":0},{\"brakeRatio\":1023},{\"brakeCount\":0},{\"overSpeedRatio\":1023},{\"overSpeedCount\":0}]"
},
{
"tripId" : "19062521016",
"driveDisstance" : 0,
"devicetime" : "2019-06-26 06:03:30",
"speeds" : "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"locations" : "[{\"latitude\":0,\"longitude\":0},{\"latitude\":0,\"longitude\":0},{\"latitude\":0,\"longitude\":0},{\"latitude\":0,\"longitude\":0},{\"latitude\":0,\"longitude\":0},{\"latitude\":0,\"longitude\":0}]",
...,
]
我希望输出如下。你知道吗
tripId | driveDisstance | devicetime | speeds | qucikTick | quickRatio | quickCount | brakeTick | brakeRatio | brakeCount | overSpeedRatio | overSpeedCount
作为列
一个tripId有60行,包括60个速度值,6个位置值和危险值。你知道吗
在最初的帖子中有一些拼写错误和由此产生的不一致,所以在这个回复中,为了说明,我使用了数据定义的拼写。
您可以使用jq将编码的字符串“解包”为JSON,例如使用以下过滤器:
对发布的数据使用-r命令行选项,上面的jq过滤器将生成:
数据帧可以从数组的数组中构建,每个内部数组都是一行。您的数据超出了
json_normalize
的容量,因此我将手动处理它:演示:
我给出:
相关问题 更多 >
编程相关推荐