SAMANTUS Python for Data Analytics — Complete Training Manual CAPSTONE PROJECT 06
← Back to Course Index

Customer Churn Analysis


On This Page

Capstone Project 6: Customer Churn Analysis


C6.1  Project Overview

This project analyzes a subscription business's customer data to understand why customers churn (cancel), and which subscription plans are most at risk.

C6.2  Business Problem

A subscription company is losing customers and wants to understand which factors — tenure, plan type — are linked to churn, so they can take targeted retention action.

C6.3  Dataset Description

ColumnDescription
customer_idUnique customer identifier
tenure_monthsNumber of months as a customer
planSubscription plan (Basic, Standard, Premium)
monthly_chargeMonthly subscription fee
churnedWhether the customer cancelled (Yes/No)

Sample scope: 400 customer records from the last 12 months.

C6.4  Objectives


C6.5  Step-by-Step Solution

C6.6  Complete Python Code

► churn_analysis.py
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

df = pd.read_csv("customer_churn.csv")
df = df.dropna(subset=['churned'])

churn_rate = (df['churned']=='Yes').mean() * 100
print(f"Overall Churn Rate: {churn_rate:.1f}%")

churn_by_plan = df.groupby('plan').apply(lambda x: (x['churned']=='Yes').mean()*100)
print("Churn Rate by Plan:\n", churn_by_plan.round(1))

sns.boxplot(data=df, x="churned", y="tenure_months")
plt.title("Tenure: Churned vs Retained")
plt.savefig("tenure_box.png")

C6.7  Expected Output

Output
Overall Churn Rate: 27.0%
Churn Rate by Plan:
Basic    35.0
Standard  22.0
Premium   15.0

C6.8  Visualizations

Figure C6.1 — Tenure comparison between churned and retained customers.
Figure C6.1 — Tenure comparison between churned and retained customers.
Figure C6.2 — Churn rate (%) by subscription plan.
Figure C6.2 — Churn rate (%) by subscription plan.

C6.9  Key Insights

C6.10  Business Recommendations

✓ Instructor Tip
This dataset structure is ideal groundwork for later machine learning modules (churn prediction models) if the institute plans to introduce ML content in future.