使用 pandas 导入 JSON 数据
在开发数据管道时,您可能需要处理非表格型的数据及数据源,例如 API 或 JSON 文件。本练习将使用 pandas 从一个 JSON 文件中提取数据。
pandas 已以 pd 导入,您将要读取的 JSON 文件位于路径 "testing_scores.json"。
本练习是课程的一部分
使用 Python 的 ETL 和 ELT
练习说明
- 更新
extract()函数,使其按记录方向将 JSON 文件读入pandas的 DataFrame。 - 将路径
testing_scores.json传入extract()函数,并将输出保存到名为raw_testing_scores的变量中。 - 打印
raw_testing_scoresDataFrame 的表头。
交互式实操练习
通过完成这段示例代码来试试这个练习。
def extract(file_path):
# Read the JSON file into a DataFrame
return pd.____(____, orient="____")
# Call the extract function with the appropriate path, assign to raw_testing_scores
____
# Output the head of the DataFrame
print(raw_testing_scores.____())