rfm = df.groupby(‘CustomerID’).agg({ ‘InvoiceDate’: lambda x: (snapshot_date — x.max()).days, ‘InvoiceNo’: ‘nunique’, ‘Revenue’: ‘sum’ })