按天计算时间偏移量 - 第 1 部分
为每笔交易计算时间偏移量,可以让您以可比的方式报告每个同群的指标。
首先,我们将使用已为您定义好的 get_date_int() 函数,为发票日期和同群日期提取并生成年份、月份、日期的整数值,共 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 中的客户细分
练习说明
- 调用
get_date_int函数并作用于InvoiceDay列,创建invoice_year、invoice_month、invoice_day对象。 - 调用
get_date_int函数并作用于CohortDay列,创建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(____, ____)