🗑️
0
Duplicates Removed
🔢
2
Columns Renamed
⚙️
200
Final Row Count
🧹 Cleaning Steps Performed
1
Remove Duplicates

Exact duplicate rows can inflate cluster sizes artificially. We use drop_duplicates() to ensure each customer record is unique.

Python 1 before = len(df) # Record count before
2 df = df.drop_duplicates() # Remove duplicate rows
3 removed = before - len(df) # Count removed
4 print(f"Removed {removed} duplicates")
Result: 0 duplicate rows removed.
2
Drop CustomerID

CustomerID is just an identifier — it carries no business information and would confuse the clustering algorithm if included.

Python 1 df = df.drop(columns=['CustomerID'])
2 print(df.columns.tolist())
Dropped: CustomerID
3
Rename Columns

Renaming columns to Python-friendly names (no spaces, no special characters) makes code cleaner and avoids indexing issues.

Python 1 df = df.rename(columns={
2     'Annual Income (k$)' : 'Annual_Income',
3     'Spending Score (1-100)' : 'Spending_Score'
4 })
Annual Income (k$) Annual_Income Spending Score (1-100) Spending_Score
4
Encode Gender

Machine learning algorithms require numeric inputs. We encode Gender as a binary column: Male=1, Female=0. This is standard label encoding for binary categoricals.

Python 1 df['Gender_Encoded'] = df['Gender'].map({'Male': 1, 'Female': 0})
2 print(df['Gender_Encoded'].value_counts())
Encoding: Male = 1   Female = 0
5
Verify Final State

After all cleaning steps, we verify: no remaining nulls, correct dtypes, and correct shape.

Python 1 print(df.shape) # Confirm row/column count
2 print(df.isnull().sum()) # Verify no nulls
3 print(df.dtypes) # Verify types
Gender 0 nulls
Age 0 nulls
Annual_Income 0 nulls
Spending_Score 0 nulls
Gender_Encoded 0 nulls
✅ Cleaned Dataset — First 10 Rows
200 rows 5 columns 0 missing values
GenderAgeAnnual_IncomeSpending_ScoreGender_Encoded
Male1915391
Male2115811
Female201660
Female2316770
Female3117400
Female2217760
Female351860
Female2318940
Male641931
Female3019720