CommencerCommencer gratuitement

Calculer le décalage temporel en jours - partie 1

Calculer le décalage temporel pour chaque transaction vous permet de présenter les indicateurs de chaque cohorte de manière comparable.

Nous allons d’abord créer 6 variables qui capturent les valeurs entières des années, mois et jours pour la date de facture (Invoice) et la date de cohorte (Cohort) à l’aide de la fonction get_date_int() déjà définie pour vous :

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

Les données online ont été chargées. Vous pouvez afficher son en-tête dans la console en appelant online.head().

Cet exercice fait partie du cours

Customer Segmentation in Python

Afficher le cours

Instructions

  • Créez les objets invoice_year, invoice_month, invoice_day en appelant la fonction get_date_int sur la colonne InvoiceDay.
  • Créez les objets cohort_year, cohort_month, cohort_day en appelant la fonction get_date_int sur la colonne CohortDay.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# 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(____, ____)
Modifier et exécuter le code