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.____())