pandas로 JSON 데이터 수집하기
데이터 파이프라인을 개발할 때는 API나 JSON 파일처럼 비정형(non-tabular) 데이터와 데이터 소스를 다뤄야 할 때가 있습니다. 이번 연습 문제에서는 pandas를 사용해 JSON 파일에서 데이터를 추출하는 방법을 연습해 보겠습니다.
pandas는 pd로 임포트되어 있으며, 수집할 JSON 파일은 "testing_scores.json" 경로에 저장되어 있습니다.
이 연습은 강의의 일부입니다
Python으로 하는 ETL과 ELT
연습 안내
extract()함수를 수정해 JSON 파일을 레코드(records) 기준으로pandasDataFrame에 읽어 들이세요.extract()함수에testing_scores.json경로를 전달하고, 결과를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.____())