Build the Customer DataFrame
Advanced · Write the code · from Predict Customer Churn: End-to-End Data Analysis (with sklearn)
From the lesson: Step 1: Create the Customer Dataset
Every data project starts with data. In a real company, you'd pull this from a database. Here, we'll build a realistic dataset as a pandas DataFrame. Our fictional telecom company tracks each customer's tenure, monthly charges, contract type, and whether they churned.
Read this part of the lessonCreate a pandas DataFrame called customers with at least 20 rows and these columns: customer_id (integers 1–20), tenure_months (integers), monthly_charges (floats or ints), contract (strings: 'Month', 'Year', or 'TwoYear'), and churned (0 or 1). Print the shape of the DataFrame and the churn rate (mean of the churned column) formatted as: Churn rate: X.XX.
More Churn Prediction exercises
- Exploratory Data AnalysisAdvanced
- Engineer New FeaturesAdvanced
- Encode and Scale FeaturesAdvanced
- Train a Logistic Regression ModelAdvanced
- Build a Confusion MatrixAdvanced
- Generate a Churn Risk ReportAdvanced
All Python exercises · 50 practice problems · Practical Projects quiz