I have several .json files that I would like to combine into one .csv file. The .json files look like this:
{"version":1.3,"people":[{"person_id":[-1],"pose_keypoints_2d":[346.096,136.31,0.822246,339.237,210.457,0.840786,264.747,203.769,0.807762,149.518,183.631,0.854263,88.6763,82.0749,0.906274,400.122,210.38,0.854152,508.225,183.228,0.898651,555.846,75.2072,0.958429,345.636,345.892,0.111406,291.626,346.153,0.194191,0,0,0,0,0,0,393.258,346.08,0.15249,0,0,0,0,0,0,339.241,136.084,0.804675,352.463,136.006,0.702916,305.539,156.42,0.639209,359.362,156.248,0.325405,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
"face_keypoints_2d":[],"hand_left_keypoints_2d":[],"hand_right_keypoints_2d":[],"pose_keypoints_3d":[],
"face_keypoints_3d":[],"hand_left_keypoints_3d":[],"hand_right_keypoints_3d":[]}]}
The code I use to load and combine files:
import json
import os
import pandas as pd
data = []
for file in os.listdir("C:/Users/ciach/PycharmProjects/CSV/"):
if file.endswith(".json"):
data2 = json.load(open(os.path.join("C:/Users/ciach/PycharmProjects/CSV/", file)))
df = pd.json_normalize(data2,record_path=['people','pose_keypoints_2d'])
data.append(df)
temp = pd.concat(data, ignore_index = True)
temp.to_csv("keypoints.csv", index=False)
After compilation with two files, I get the following results in .csv file (all values are in one column):
338.938
156.226
...
0.000000
0.000000
I would like to get the values only from the list 'pose_keypoints_2d' in one row for each .json file instead of one whole column from all files. Something like that:
338.938000 156.226000 0.322833 ... 0.000000 0.000000
346.096000 136.310000 0.822246 ... 0.000000 0.000000
print(data)?338.938000 156.226000 0.322833 ... 0.000000 0.000000???