Editor

Exploratory Data Analysis

Advanced · Write the code · from Predict Customer Churn: End-to-End Data Analysis (with sklearn)

From the lesson: Step 2: Explore and Understand the Data

Before building any model, you need to understand your data. What does the average customer look like? Are there differences between customers who stayed and those who left? Exploratory Data Analysis (EDA) answers these questions.

Read this part of the lesson

Given the DataFrame df (already created for you), perform exploratory analysis. Print: (1) the output of df.describe(), (2) the value counts of the contract column, and (3) the mean tenure_months and monthly_charges grouped by churned. Print a label before each output: "Summary Statistics:", "Contract Counts:", and "Churn Group Means:".

import pandas as pd
data = {
'tenure_months': [2, 34, 5, 45, 12, 1, 60, 8, 24, 48,
3, 36, 7, 52, 15, 2, 42, 10, 30, 6],
'monthly_charges': [70, 45, 85, 30, 65, 90, 25, 75, 55, 35,
88, 40, 78, 28, 60, 92, 32, 72, 50, 82],
'contract': ['Month', 'Year', 'Month', 'TwoYear', 'Month', 'Month', 'TwoYear',
'Month', 'Year', 'TwoYear', 'Month', 'Year', 'Month', 'TwoYear',
'Year', 'Month', 'TwoYear', 'Month', 'Year', 'Month'],
'churned': [1, 0, 1, 0, 1, 1, 0, 1, 0, 0,
1, 0, 1, 0, 0, 1, 0, 1, 0, 1]
}
df = pd.DataFrame(data)
# Print summary statistics, contract value counts, and churn group means

More Churn Prediction exercises

All Python exercises · 50 practice problems · Practical Projects quiz