spend is a DataFrame with user_id, day (a "YYYY-MM-DD" string) and amount. Each user has at most one row per day, but users skip days, and the rows arrive in no particular order.
For every row, compute amount_7d: the user's total amount over the 7 calendar days ending on that day — the day itself and the 6 days before it. Days the user has no row for count as nothing.
Return a DataFrame with columns user_id, day, amount, amount_7d, sorted by user_id, then day, with a fresh 0..n−1 index.
Python 3.13 in your browser — the standard library plus pandas and numpy; no pip installs.