
Monthly approved spend
mediumMonthly approved spend
Visa Pandas Interview Question
Visa's issuer reports show approved card spend per month and how it changed from the month before.
Use the card_transactions DataFrame and count approved transactions only. Return each month as a string like "2024-01", the total spend as approved_spend, rounded to 2 decimal places, and the percentage change from the previous month as pct_change, rounded to 1 decimal place. The first month has no previous month, so leave its change empty. Sort the rows by month. Assign the answer to result.
Asked of
- Data Analyst
- Product Analyst
- Business Analyst
- Analytics Engineer
- Data Scientist
card_transactionsDataFrame18 rows
| Column Name | Type |
|---|---|
| transaction_id | int64 |
| card_id | int64 |
| merchant_country | str |
| merchant_category | str |
| amount_usd | float64 |
| transaction_date | str |
| status | str |
card_transactionsExample Input
| transaction_id | card_id | merchant_country | merchant_category | amount_usd | transaction_date | status |
|---|---|---|---|---|---|---|
| 3001 | 1 | United States | Groceries | 84.2 | 2024-01-04 | approved |
| 3002 | 2 | France | Travel | 640 | 2024-01-09 | approved |
| 3003 | 3 | Canada | Restaurants | 52.75 | 2024-01-15 | approved |
| 3004 | 4 | Spain | Travel | 410.3 | 2024-01-21 | declined |
| 3005 | 6 | Japan | Electronics | 1299 | 2024-01-28 | approved |
| 3006 | 5 | Canada | Groceries | 96.4 | 2024-02-02 | approved |
| 3007 | 1 | Mexico | Travel | 275 | 2024-02-08 | approved |
| 3008 | 3 | United States | Electronics | 899.99 | 2024-02-13 | approved |
| 3009 | 2 | United States | Restaurants | 68.1 | 2024-02-17 | approved |
| 3010 | 4 | United Kingdom | Groceries | 58.6 | 2024-02-22 | approved |
| 3011 | 6 | United States | Travel | 520 | 2024-02-27 | declined |
Example Output
| month | approved_spend | pct_change |
|---|---|---|
| 2024-01 | 2075.95 | NULL |
| 2024-02 | 1398.09 | -32.7 |
Explanation
January's approved spend is 2,075.95. The declined transaction that month is not counted. February's approved spend is 1,398.09, which is 32.7% lower than January, so its change is -32.7.
The example above is a small slice of the data. Your code runs against the full DataFrames.
Company
Visa
Difficulty
medium
Topic
dates
Language
Pandas
Your code
Loading Python in the background. You can start writing.