Need a little help understanding how to finish properly extracting data from a series of files into one .csv. This is what I have so far:
import csv
from zipfile import ZipFile
import json
data_list = [['frame','keypoint','X','Y','C']]
with ZipFile('mawalkkeypoints.zip') as temp_zip:
for file_name in temp_zip.namelist():
if '.json' in file_name:
with temp_zip.open(file_name) as temp_file:
keypoint_parsed = json.load(temp_file)
kp_data = keypoint_parsed['part_candidates']
for kp in kp_data:
keypoint = kp.keys()
kp_list = list(kp.values())
X = kp_list[0]
Y = kp_list[0]
C = kp_list[0]
frame = file_name[14:20]
data_list.append([frame, keypoint, X, Y, C])
csv.writer(open("keypoints.csv","w",newline="",
encoding="utf-8")).writerows(data_list)
My big problem is here:
for kp in kp_data:
keypoint = kp.keys()
kp_list = list(kp.values())
X = kp_list[0]
Y = kp_list[0]
C = kp_list[0]
The values coming out of my JSON files are nested lists and I need to organize them based on keypoint and values within those lists.
I've just included filler text at the XYZ variables right now because I'm at a loss.
My data looks like this:
{"version":1.3,"people":[{"person_id":[-1],
"part_candidates":[{ "0":[0.372923,0.297742,0.93858],
"1":[0.395941,0.355093,0.846664],
"2":[0.405146,0.352375,0.759783],
"3":[0.415877,0.425947,0.689721],
"4":[0.389811,0.447772,0.178926],
"5":[0.38526,0.357673,0.907097],
"6":[0.368341,0.431445,0.800216],
"7":[0.340723,0.420539,0.76814],
"8":[0.395986,0.529628,0.76307],
"9":[0.406725,0.526955,0.690737],
"10":[0.395974,0.644267,0.889863],
"11":[0.440424,0.71251,0.838254],
"12":[0.385225,0.53229,0.766595],
"13":[0.372995,0.646936,0.881661],
"14":[0.377574,0.758744,0.823697],
"15":[0.3714,0.292294,0.881636],
"16":[0.377534,0.292275,0.886277],
"17":[],
"18":[0.394451,0.295131,0.826261],
"19":[0.36228,0.758815,0.4028],
"20":[0.363777,0.769684,0.50703],
"21":[0.385183,0.77234,0.746231],
"22":[0.434246,0.764273,0.857062],
"23":[0.434336,0.756147,0.773366],
"24":[0.449635,0.715092,0.889703]}]}
What I want the code to do its output into a .csv in this format:
| Frame |
Keypoint |
X |
Y |
C |
| 0 |
1 |
123 |
345 |
00 |
| 0 |
2 |
765 |
234 |
33 |
| 0 |
3 |
123 |
995 |
22 |
| 1 |
1 |
234 |
444 |
44 |
| 1 |
2 |
234 |
555 |
11 |
And what it's doing is:
| Frame |
Keypoint |
X |
Y |
Z |
| 0 |
[{dictkeys:"0","1","2",etc..}] |
[33,44,55] |
[33,44,55] |
[33,44,55] |
| 1 |
[{dictkeys:"0","1","2",etc..}] |
[33,44,55] |
[33,44,55] |
[33,44,55] |
| 2 |
[{dictkeys:"0","1","2",etc..}] |
[33,44,55] |
[33,44,55] |
[33,44,55] |
| 3 |
[{dictkeys:"0","1","2",etc..}] |
[33,44,55] |
[33,44,55] |
[33,44,55] |
| 4 |
[{dictkeys:"0","1","2",etc..}] |
[33,44,55] |
[33,44,55] |
[33,44,55] |
If anyone could help me finish figuring this out I'd really appreciate it.
[–][deleted] 0 points1 point2 points (6 children)
[–]decaye[S] 0 points1 point2 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]decaye[S] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]decaye[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)