Как изменить структуру JSON с помощью Python?
Данные приходят в таком формате:
{
"data": {
"columns": [
"time",
"weight",
"power",
"position",
"home",
"wear",
"type",
"color",
"year",
"name"
],
"values": [
"2022-08-07T17:48:00",
1,
1,
1,
1,
0,
1,
0,
2016,
665,
"2022-08-07T17:50:00",
2,
2,
2,
2,
2,
2,
0,
2016,
665
]
}
}
Нужно получить:
{
"data": {
"columns": [
"time",
"weight",
"power",
"position",
"home",
"wear",
"type",
"color",
"year",
"name"
],
"values": [
["2022-08-07T17:48:00",
1,
1,
1,
1,
0,
1,
0,
2016,
665],
["2022-08-07T17:50:00",
2,
2,
2,
2,
2,
2,
0,
2016,
665]
]
}
}
Написал код. Но он очень долго преобразует
df_values = dt["data"]["values"]
num_row = (len(df_values))//10
for n in range(num_row):
df_temp = df_values[:10]
df_values = df_values[10:]
df.append(df_temp)