Interview Query

Customer Analysis

Upvote
0
Downvote
Save
Mark Completed
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.

Example:

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: Distribution of 2X - Y
.....
Loading editor
Use Shift + Enter to run

Comments

Loading comments