Challenge

Project 2 - EDA on Vehicle Insurance Customer Data

Project 2 โ€“ EDA on Vehicle Insurance Customer Data"


๐Ÿ”น Step 1: Import & Add Column Names

python

import pandas as pd import numpy as np # Load your datasets # customer_df = pd.read_csv('customer.csv') # policy_df = pd.read_csv('customer_policy.csv') # Add proper column names customer_df.columns = [ 'customer_id', 'Gender', 'age', 'driving_licence_present', 'region_code', 'previously_insured', 'vehicle_age', 'vehicle_damage' ] policy_df.columns = [ 'customer_id', 'annual_premium', 'sales_channel_code', 'vintage', 'response' ]


๐Ÿ”น Step 2: Data Quality Checks & Cleaning

2.i Handling Nulls

python

# Null summary print(customer_df.isnull().sum()) print(policy_df.isnull().sum()) # Drop rows with null customer_id customer_df.dropna(subset=['customer_id'], inplace=True) policy_df.dropna(subset=['customer_id'], inplace=True) # Fill numeric nulls with mean customer_df.fillna(customer_df.select_dtypes(include='number').mean(), inplace=True) policy_df.fillna(policy_df.select_dtypes(include='number').mean(), inplace=True) # Fill categorical nulls with mode for df in [customer_df, policy_df]: for col in df.select_dtypes(include='object'): df[col].fillna(df[col].mode()[0], inplace=True)

2.ii Outlier Handling (IQR)

python

def treat_outliers(df): for col in df.select_dtypes(include='number'): Q1 = df[col].quantile(0.25) Q3 = df[col].quantile(0.75) IQR = Q3 - Q1 lower = Q1 - 1.5 * IQR upper = Q3 + 1.5 * IQR df.loc[(df[col] < lower) | (df[col] > upper), col] = df[col].mean() treat_outliers(customer_df) treat_outliers(policy_df)

2.iii Remove Whitespaces & Case Correction

python

def clean_text_cols(df): for col in df.select_dtypes(include='object'): df[col] = df[col].str.strip().str.lower() clean_text_cols(customer_df) clean_text_cols(policy_df)

2.iv Dummies (optional for modeling)

python

# customer_df = pd.get_dummies(customer_df, drop_first=True) # policy_df = pd.get_dummies(policy_df, drop_first=True)

2.v Drop Duplicates

python
customer_df.drop_duplicates(inplace=True) policy_df.drop_duplicates(inplace=True)


๐Ÿ”น Step 3: Create Master Table

python

master_df = pd.merge(customer_df, policy_df, on='customer_id', how='inner') master_df.head()


๐Ÿ”น Step 4: Business Insights

4.i Gender-wise Avg Premium

python

master_df.groupby('Gender')['annual_premium'].mean()

4.ii Age-wise Avg Premium

python

master_df.groupby('age')['annual_premium'].mean()

4.iii Gender Balance Check

python

master_df['Gender'].value_counts()

4.iv Vehicle Age-wise Avg Premium

python

master_df.groupby('vehicle_age')['annual_premium'].mean()


๐Ÿ”น Step 5: Correlation Between Age & Annual Premium

python

correlation = master_df['age'].corr(master_df['annual_premium']) print("Correlation:", correlation) # Interpretation if correlation > 0.5: print("Strong positive relationship") elif correlation < -0.5: print("Strong negative relationship") else: print("No significant relationship")

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.