Quick Overview

This question evaluates data manipulation and aggregation skills in Python (pandas) and SQL by testing transactional filtering, handling of refunds, and computation of per-user total spending.

Compute Total Spent in 2023 Excluding Refunds

Company: Visa

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

transactions +----------------+---------+-------------+--------+------------------+ | transaction_id | user_id | merchant_id | amount | transaction_date | +----------------+---------+-------------+--------+------------------+ | 1 | 101 | 2001 | 120 | 2023-01-10 | | 2 | 102 | 2002 | -20 | 2023-02-14 | | 3 | 101 | 2001 | 30 | 2022-12-31 | | 4 | 103 | 2003 | 55 | 2023-03-05 | | 5 | 101 | 2002 | 75 | 2023-04-17 | +----------------+---------+-------------+--------+------------------+ ##### Scenario Visa analytics role – technical round requiring the same data-manipulation task solved first in Python and then in SQL. ##### Question Using Python (pandas), compute each user’s total amount spent in 2023, excluding refunds (negative amounts). Return user_id and total_spent sorted by total_spent descending. Rewrite the same solution in SQL, using a CTE and GROUP BY. ##### Hints Filter dates, ignore negative amounts, aggregate, sort.

Quick Answer: This question evaluates data manipulation and aggregation skills in Python (pandas) and SQL by testing transactional filtering, handling of refunds, and computation of per-user total spending.

Loading coding console...