1. 학습
  2. /
  3. 강의
  4. /
  5. Python을 활용한 고객 세분화

Connected

연습 문제

일 단위 시간 오프셋 계산 - 1단계

각 거래의 시간 오프셋을 계산하면 각 코호트에 대해 지표를 서로 비교 가능한 방식으로 보고할 수 있어요.

먼저, 이미 정의되어 있는 get_date_int() 함수를 사용해 Invoice 날짜와 Cohort 날짜의 연도, 월, 일을 정수로 추출하는 6개의 변수를 만들겠습니다:

def get_date_int(df, column):
    year = df[column].dt.year
    month = df[column].dt.month
    day = df[column].dt.day
    return year, month, day

online 데이터가 로드되어 있으니, online.head()를 호출해 콘솔에 헤더를 출력해 볼 수 있어요.

지침

100 XP
  • InvoiceDay 열에 get_date_int 함수를 적용해 invoice_year, invoice_month, invoice_day 객체를 생성하세요.
  • CohortDay 열에 get_date_int 함수를 적용해 cohort_year, cohort_month, cohort_day 객체를 생성하세요.