Ivy Professional School
Rating
Learning/Python Data Drill #4

Customer Profitability & Loyalty Analysis

Last updated

Analyze customer profitability, loyalty, spending behavior, profit margin, and high-value customer status.

PythonIntermediatePandasNumPyGroupBySegmentationRanking

Your Objective

Analyze customer profitability, loyalty, spending behavior, profit margin, and high-value customer status.

The Setup

Your dataset contains customer_orders with repeated customer orders, order amounts, city, and profit values.

Table Schema

customer_orders
ColumnTypeKey / Notes
customer_idINTUnique customer ID
customer_nameVARCHAR(50)Customer name
cityVARCHAR(50)Customer city
order_amountFLOATOrder amount
profitFLOATProfit earned from the order

Sample Data

customer_orders — 10 rows

customer_idcustomer_namecityorder_amountprofit
101RahulMumbai150002500
102PriyaDelhi120001800
101RahulMumbai180003200
103AmanKolkata8000900
104SnehaBangalore250004200
102PriyaDelhi140002200
105VikramPune300005500
101RahulMumbai220004100
103AmanKolkata110001300
105VikramPune270004800

Your Task

Calculate total sales, total profit, average order value, and total orders for each customer. Assign customer segments using sales thresholds. Calculate profit margin percentage. Rank customers based on total profit. Identify high-value customers where profit margin is above 15% and total orders are at least 2.

Your output should look like this (partial example):

customer_idcustomer_nametotal_salestotal_profittotal_orderscustomer_segmentprofit_rankhigh_value_customer
105Vikram57000103002Platinum1Yes
101Rahul5500098003Platinum2Yes
........................

Python Hint

  • →Aggregate at customer level before applying segment, margin, and rank logic.
Explore Enterprise Solutions