You are preparing training data for a churn model. Each user's features must be computed only from what was known on a cutoff date, and each label must describe what happened in the window right after it.
Write build_churn_table(events, cutoff, window_days).
events: a pandas DataFrame with columns user_id (int), event_date (string YYYY-MM-DD) and amount (float). Rows are in no particular order.cutoff: a string YYYY-MM-DD. Events on or before the cutoff are history; events after it are the future.window_days: a positive int .Include every user with at least one history event. For each, compute:
recency_days: days from the user's last history event to the cutoff (0 if it is on the cutoff)frequency: number of history eventsmonetary: sum of history amount, rounded to 2 decimalsrecent_events: number of history events in the last days, that is dated in label, from the count of events dated in :
'hard' if 'soft' if and (activity fell to under half)'active' otherwiseReturn a DataFrame with columns user_id, recency_days, frequency, monetary, recent_events, label, sorted by user_id, with a 0-based index.