시작하기무료로 시작하기

데이터 파이프라인에서 로깅하기

이번 연습 문제에서는 이전 동영상에서 작성했던 함수를 다시 살펴보고, 해당 함수에 로깅을 추가하는 연습을 해보겠습니다. 로깅을 추가하면 오류를 해결하거나 로직을 변경할 때 큰 도움이 됩니다!

pandas는 pd로 임포트되어 있습니다. 이와 함께 logging 모듈도 임포트되어 있으며, 기본 로그 수준은 "debug"로 설정되어 있습니다.

이 연습은 강의의 일부입니다

Python으로 하는 ETL과 ELT

강의 보기

연습 안내

  • 변환 작업 이후에 "Transformed 'Order Date' column to type 'datetime'." 문자열을 전달하여 info 수준의 로그를 생성하세요.
  • 필터링 전후로 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)
코드 편집 및 실행