Interview Query

Customer Analysis

0
Have you seen this question before?

You’re given a dataframe containing sales data from a grocery store chain with columns for customer ID, gender, and date of sale.

Create a new dataset with summary level information on their purchases including the columns:

  • customer_id
  • gender
  • most_recent_sale
  • order_count

most_recent_sale should display the date of the customer’s most recent purchase. order_count should display the total number of purchases that the customer has made.

Input:

import pandas as pd

customers = {"customer_id" : [5156, 2982, 1011, 3854, 2982], "Gender" : ["m", "f", "m", "f", "f"], "Date of Sale" : ["2021-01-04", "2021-02-15", "2021-03-01", "2021-03-21", "2021-04-12"]}

customer_df = pd.DataFrame(customers)

Output:

customer_id gender most_recent_sale order_count
1011 m 2021-03-01 1
2982 f 2021-04-12 2
3854 f 2021-03-21 1
Next question: Stranded Miner
Python 3.9.6
Loading editor