LoslegenKostenlos loslegen

Calculate time offset in days - part 1

Calculating time offset for each transaction allows you to report the metrics for each cohort in a comparable fashion.

First, we will create 6 variables that capture the integer value of years, months and days for Invoice and Cohort Date using the get_date_int() function that's been already defined for you:

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

The online data has been loaded, you can print its header to the console by calling online.head().

Diese Übung ist Teil des Kurses

Customer Segmentation in Python

Kurs anzeigen

Anleitung zur Übung

  • Create invoice_year, invoice_month, invoice_day objects by calling get_date_int function on InvoiceDay column.
  • Create cohort_year, cohort_month, cohort_day objects by calling get_date_int function on CohortDay column.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# 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(____, ____)
Code bearbeiten und ausführen