Revenue by plan and month

reshaping

Revenue by plan and month

Shopify Pandas Interview Question

Shopify's subscription revenue comes from merchants on three tiers, and which tier they sit on matters more than how many of them there are. A merchant moving from Advanced down to Basic takes nine tenths of its revenue with it. Finance tracks what each plan billed each month, so a tier losing ground is visible before the total moves.

Using the subscriptions DataFrame, return one row per month: keep active_month as a column, then one column per plan named Advanced, Basic and Shopify, holding the subscription revenue billed on that plan that month. A plan with nothing in a month shows 0. Assign the answer to result.

Asked of

  • Data Analyst
  • Business Analyst
  • Product Analyst
  • Analytics Engineer
  • Data Scientist

subscriptionsDataFrame26 rows

Column NameType
record_idint64
merchant_idstr
active_monthstr
planstr
mrrfloat64

subscriptionsExample Input

record_idmerchant_idactive_monthplanmrr
1101M012024-01-01Basic29
1102M012024-02-01Basic29
1103M012024-03-01Shopify79
1104M012024-06-01Shopify79
1105M012024-07-01Advanced299
1106M012024-08-01Advanced299
1107M022024-01-01Shopify79
1108M022024-02-01Shopify79
1109M022024-03-01Shopify79
1110M022024-04-01Shopify79
1111M022024-05-01Basic29
1112M022024-06-01Basic29
1113M022024-07-01Basic29
1114M022024-08-01Basic29

Example Output

active_monthAdvancedBasicShopify
2024-01-0102979
2024-02-0102979
2024-03-0100158
2024-04-010079
2024-05-010290
2024-06-0102979
2024-07-01299290
2024-08-01299290

Explanation

In March both merchants in the example were on the Shopify plan, the middle tier at 79 a month, so that column holds 158 and the other two hold 0. Nobody on a plan is 0 revenue for that month, not a missing number.

The example above is a small slice of the data. Your code runs against the full DataFrames.