คำนวณค่า offset ของเวลาในหน่วยวัน - ส่วนที่ 1
การคำนวณค่า offset ของเวลาสำหรับแต่ละธุรกรรมช่วยให้สามารถรายงานเมตริกของแต่ละ cohort ได้อย่างสอดคล้องกัน
เราจะสร้างตัวแปร 6 ตัวเพื่อเก็บค่าจำนวนเต็มของปี เดือน และวัน สำหรับทั้ง Invoice Date และ Cohort Date โดยใช้ฟังก์ชัน get_date_int() ที่เตรียมไว้ให้แล้ว:
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()
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การแบ่งกลุ่มลูกค้าด้วย Python
คำแนะนำการฝึกหัด
- สร้างออบเจกต์
invoice_year,invoice_month,invoice_dayโดยเรียกฟังก์ชันget_date_intบนคอลัมน์InvoiceDay - สร้างออบเจกต์
cohort_year,cohort_month,cohort_dayโดยเรียกฟังก์ชันget_date_intบนคอลัมน์CohortDay
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Get the integers for date parts from the `InvoiceDay` column
____, ____, ____ = get_date_int(____, ____)
# Get the integers for date parts from the `CohortDay` column
____, ____, ____ = get_date_int(____, ____)