데이터 파이프라인에서 로깅하기
이 연습에서는 앞선 영상에서 작성한 함수를 다시 살펴보고, 함수에 로깅을 추가하는 연습을 해볼 거예요. 로깅은 오류를 진단하거나 로직을 수정할 때 큰 도움이 됩니다!
pandas는 pd로 임포트되어 있어요. 여기에 더해 logging 모듈도 임포트되어 있으며, 기본 로그 수준은 "debug"로 설정되어 있습니다.
이 연습은 강의의 일부입니다
Python으로 ETL과 ELT
연습 안내
- 변환이 끝난 뒤, 다음 문자열을 전달하여 info 수준 로그를 생성하세요:
"Transformed 'Order Date' column to type 'datetime'." - 필터링 전후의 DataFrame
.shape를 debug 수준으로 로깅하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
def transform(raw_data):
raw_data["Order Date"] = pd.to_datetime(raw_data["Order Date"], format="%m/%d/%y %H:%M")
clean_data = raw_data.loc[raw_data["Price Each"] < 10, :]
# Create an info log regarding transformation
logging.____("Transformed 'Order Date' column to type 'datetime'.")
# Create debug-level logs for the DataFrame before and after filtering
____(f"Shape of the DataFrame before filtering: {raw_data.shape}")
____(f"Shape of the DataFrame after filtering: {clean_data.shape}")
return clean_data
clean_sales_data = transform(raw_sales_data)