始める無料で始める

日数のタイムオフセットを計算する - パート1

各取引ごとのタイムオフセットを計算すると、各コホートの指標を同じ基準で比較できるようになります。

まず、すでに定義済みの get_date_int() 関数を使って、Invoice と Cohort Date について年・月・日の整数値を取得する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() を呼び出して先頭行をコンソールに表示できます。

この演習はコースの一部です

Pythonで学ぶカスタマーセグメンテーション

コースを見る

演習の手順

  • InvoiceDay 列に対して get_date_int 関数を呼び出し、invoice_yearinvoice_monthinvoice_day オブジェクトを作成します。
  • CohortDay 列に対して get_date_int 関数を呼び出し、cohort_yearcohort_monthcohort_day オブジェクトを作成します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# 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(____, ____)
コードを編集して実行