Monthly approved spend

dates

Monthly 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 NameType
transaction_idint64
card_idint64
merchant_countrystr
merchant_categorystr
amount_usdfloat64
transaction_datestr
statusstr

card_transactionsExample Input

transaction_idcard_idmerchant_countrymerchant_categoryamount_usdtransaction_datestatus
30011United StatesGroceries84.22024-01-04approved
30022FranceTravel6402024-01-09approved
30033CanadaRestaurants52.752024-01-15approved
30044SpainTravel410.32024-01-21declined
30056JapanElectronics12992024-01-28approved
30065CanadaGroceries96.42024-02-02approved
30071MexicoTravel2752024-02-08approved
30083United StatesElectronics899.992024-02-13approved
30092United StatesRestaurants68.12024-02-17approved
30104United KingdomGroceries58.62024-02-22approved
30116United StatesTravel5202024-02-27declined

Example Output

monthapproved_spendpct_change
2024-012075.95NULL
2024-021398.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.