开始使用免费开始使用

按天计算时间偏移量 - 第 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_yearinvoice_monthinvoice_day 对象。
  • 调用 get_date_int 函数并作用于 CohortDay 列,创建 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(____, ____)
编辑并运行代码