Ingesting JSON data with pandas
When developing a data pipeline, you may have to work with non-tabular data and data sources, such as APIs or JSON files. In this exercise, we'll practice extracting data from a JSON file using pandas.
pandas has been imported as pd, and the JSON file you'll ingest is stored at the path "testing_scores.json".
This exercise is part of the course
ETL and ELT in Python
Exercise instructions
- Update the
extract()function read a JSON file into apandasDataFrame, orienting by records. - Pass the path
testing_scores.jsonto theextract()function, and store the output to a variable calledraw_testing_scores. - Print the head of the
raw_testing_scoresDataFrame.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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.____())