1. Learn
  2. /
  3. Kurser
  4. /
  5. 使用 Python 的 ETL 和 ELT

Connected

övning

遍历字典

当 JSON 数据被加载到字典后,您可以使用 Python 的内置工具来遍历其键和值。

文件 "nested_school_scores.json" 已读取为字典,并存入变量 raw_testing_scores,其结构如下:

{
    "01M539": {
        "street_address": "111 Columbia Street",
        "city": "Manhattan",
        "scores": {
              "math": 657,
              "reading": 601,
              "writing": 601
        }
  }, ...
}

Instruktioner 1/3

undefined XP
  • 1
    • 遍历 raw_testing_scores 字典的键。
    • 将每个键加入到 raw_testing_scores_keys 列表中。
  • 2
    • 现在,遍历从 raw_testing_scores 字典获取的值列表。
  • 3
    • 最后,同时遍历 raw_testing_scores 字典的键和值。