日数のタイムオフセットを計算する - パート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_year、invoice_month、invoice_dayオブジェクトを作成します。CohortDay列に対してget_date_int関数を呼び出し、cohort_year、cohort_month、cohort_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(____, ____)