Acquisire dati JSON con pandas
Quando sviluppi una data pipeline, potresti dover lavorare con dati e sorgenti non tabulari, come API o file JSON. In questo esercizio, metterai in pratica l'estrazione di dati da un file JSON usando pandas.
pandas è stato importato come pd e il file JSON che andrai ad acquisire si trova al percorso "testing_scores.json".
Questo esercizio fa parte del corso
ETL and ELT in Python
Istruzioni dell'esercizio
- Aggiorna la funzione
extract()per leggere un file JSON in un DataFramepandas, con orientamento per record. - Passa il percorso
testing_scores.jsonalla funzioneextract()e salva l'output in una variabile chiamataraw_testing_scores. - Stampa la testa (head) del DataFrame
raw_testing_scores.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
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.____())