Project 2 - EDA on Vehicle Insurance Customer Data
# Step 1 : Reading data
import pandas
tabel1 = pandas.read_csv("customer_details.csv")
tabel2 = pandas.read_csv("customer_policy_details.csv")
print(tabel1.head())
print(tabel2.head())
# Step 2: Checking and Cleaning the data
# 2.1 Null values
# 2.1.1 Tabel1
tabel1_labels={'0':'customer_id','1':'gender','2':',age','3':'driving_licence_present',4',':'region_code','5':'previously_insured',
'6':'vehicle_age'7':'vehicle_damage'}
# 2.1.1.1 counting the null values of each column of tabel1
for i in range(table1.shape[1]):
print(f"number of cells of {tabel1_labels[str(i)]} with null values =
{table1[str1(i)].isnull().sum()}")
tabel1.info()
# 2.1.1.2 dropping rows with null customer_id of tabel1
tabel1.dropna(subset=['0'],inplace=true)
print(f"number of cells of {tabel1_labels[str(0)} with null values =
{table1[str(0)].isnull().sum()}")
# 2.1.1.3 replacing all null values for numeric column by mean of tabel1
for i in range(2,6):
tabel1[str1(i)].fillna(tabel1[str(i)].mean(),inplace=True
{tabel1[str(i)].isnull().sum()}")
# 2.1.1.4 replacing all null values for Catergorical value by mode of tabel1
for i in range(1,6,7):
tabel1[str(i)].fillna(tabel1[str(i)].mode()[0],inplace=True)
print(f"number of cells of {tabel1_labels[str(i)]} with null values =
{tabel1[str(i).isnull().sum()}")
# 2.1.2 Tabel2
tabel2_labels={'0':'customer_id',':'annual_premium_INR',
'2':'sales_channel_code','3':'vintage','4':'response'}
# 2.1.2.1 counting the null values of each column of table2
for i in range (table2.shape[1]):
print(f"number of cells of {tabels2_labels[str(i)]} with null values is
{tabel2[str(i)].isnull().sum()}")
tabel2.info()
# 2.1.2.2 dropping rows with null customer_id of table2
tabel2.dropna(subset=['0'],inplace=True)
print(f"number of cells of {tabel1_labels[str(0)]} with null values =
{tabel2[str(0)].isnull().sum()}")
# 2.1.2.3 replacing all null values for numeric columns by mean of table2
for i in range(1,5):
# 2.2 Outliers
# 2.2.1 Tabel1
tabel1_limits ={}
for i in range(2,6):
computations = tabel1[str(i).describe(percentiles=[.25,.75])
mean = computations.values[1]
Q1 = computations.values[4] #25%
Q3 = computations.values[6] #75%
IQR =Q3-Q1
II = Q1-1.5*IQR #lower limit
hI = Q3+1.5*IQR # higher limit
tabel1_limits[str(i)] = (II,hI)
tabel_limits
# 2.2.1.1 generating a summary of count of all the outliers column wise of tabel1
(only for numeric columns)
tabel1_outliers = {'2':0,'3':0,'4':0','5':0}
for j in tabel1.index:
for i in range(2,6):
if (tabel1_limits[str(i)][0]!=tabel1_limits[str(i)][1]) and(tabel1.loc[j,
str(i)]>tabel1_limits[str(i)][1] or tabel1.loc[j,str(i)]<tabel1_limits[str(i)][0]):
tabel1_outliers
# 2.1.2.2 replacing all outliers values for numeric columns by mean for tabel1
# though as can be seen above,there are no outliers at all!, anyways the code is following
for j in tabel1.index:
for i in range(2,6):
if tabel1.loc[j,str(i)]<tabel1_limits[str(i)][0]:
tabel1.loc[j,str(i)]=tabel1[str(i)].mean()
if tabel1.loc[j,str(i)]>tabel_limits[str(i)][1]:
table1.loc[j,str(i)]=tabel1[str(i)].mean()