teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追加

2020/12/08 07:45

投稿

bsdfan
bsdfan

スコア4925

answer CHANGED
@@ -2,13 +2,16 @@
2
2
 
3
3
  キーが存在しない場合に空でいいならこんな感じでしょうか。
4
4
 
5
+ リスト(`data['people']`)の部分でもエラーが出ているようなので、リストの中身があるかもチェックしましょう。
6
+
5
7
  ```python
6
8
  i = 0
7
9
  for l in files:
8
10
  with open(l) as f:
9
11
  data = json.load(f)
10
12
 
11
- if 'pose_keypoints_2d' in data['people'][0]:
13
+ # if 'pose_keypoints_2d' in data['people'][0]:
14
+ if data['people'] and ('pose_keypoints_2d' in data['people'][0]):
12
15
  data = np.array(data['people'][0]['pose_keypoints_2d']).reshape(-1, 3)
13
16
  else:
14
17
  data = []