Challenge

Project 2 - EDA on Vehicle Insurance Customer Data

import pandas as pd
df1=pd.read_csv('C:\\Users\\sandy\\Documents\\project_1\\customer_details.csv')
df2=pd.read_csv('C:\\Users\\sandy\\Documents\\project_1\\customer_policy_details.csv')
print(df1.head())
print(df2.head())

1.#file1

df1.columns['customer_id','gender','age','driving_liscence_presence','region_code','previously_insured','vehicle_age','vehicle_damage']

df1.dropna(subset=['customer_id'],inplace=True)

print(df1.isnull().sum())

for column in df1[['age', 'driving_liscence_presence', 'region_code','previously_insured']]:
mean = df1[column].mean()
df1[column] = df1[column].fillna(mean)

for column in df1[['gender', 'vehicle_age', 'vehicle_damage']]:
mode = df1[column].mode()
df1[column] = df1[column].fillna(mode)

#file2

df2.columns=['customer_id','annual_premium_INR','sales_channel_code','vintage','response']

df2.dropna(subset=['customer_id'],inplace=True)

for column in df2[['annual_premium_INR','sales_channel_code','vintage','response']]:
mean = df2[column].mean()
df2[column] = df2[column].fillna(mean)

#Outliers

df1['age'].describe()

df1['driving_liscence_presence'].describe()

df1['previously_insured'].describe()

df1['region_code'].describe()

df2['annual_premium_INR'].describe()

df2['sales_channel_code'].describe()

df2['vintage'].describe()

df2['response'].describe()

# Remove whitespace
df1.apply(lambda x: x.str.strip() if x.dtype=="object" else x)

df2.apply(lambda x: x.str.strip() if x.dtype=="object" else x)

# case correction
df1.apply(lambda x: x.str.lower() if x.dtype=="object" else x)

df2.apply(lambda x: x.str.lower() if x.dtype=="object" else x)

# dummy variable
df1_dummies = pd.get_dummies(df1, columns=['gender'])
df1_dummies.head()

df2_dummies = pd.get_dummies(df2, columns=['response'])
df2_dummies.head()

#drop duplicates

df1.drop_duplicates(inplace= True)

df2.drop_duplicates(inplace= True)

# creating master table
data=pd.merge(df1,df2,on='customer_id')

data

# Gender wise average annual premium
data.groupby('gender')['annual_premium_INR'].mean()

# Age wise average annual premium
result = data.groupby('age')['annual_premium_INR'].mean()
import matplotlib.pyplot as pyplot
result.plot()
pyplot.show()

# Is your data balanced between the genders?
print(f"male to female ration is {round(data['gender'].value_counts()[0]/data['gender'].value_counts()[1],2)}")
print(f"generally, the standard is: \n balanced data ratio: {50/50}\n slightly balanced data ratio: {round(55/45,2)}-{60/40} \n imbalanced data ratio: {80/20}-{90/10}")

# Vehicle age wise average annual premium.
result1 = data.groupby('vehicle_age')['annual_premium_INR'].mean()
import matplotlib.pyplot as pyplot
result1.plot()
pyplot.show()

# Is there any relation between Person Age and annual premium?
n = data['age'].corr(data['annual_premium_INR'])
if n<-0.5:
print("Strong negative relationship")
if n>0.5:
print("Strong positive relationship")
if n>-0.5 and n<0.5:
print("There is no 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.