-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheda
More file actions
79 lines (45 loc) · 1.22 KB
/
Copy patheda
File metadata and controls
79 lines (45 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import numpy as np;
import pandas as pd;
import matplotlib.pyplot as plt;
import seaborn as sns;
df = pd.read_csv('D9-titanic_dataset.csv')
df.head()
df.columns
df.info()
df.info()
df.shape
df.describe()
df.isnull().sum()
df['Age'] = df['Age'].fillna(df['Age'].mean())
df.drop('Cabin',axis = 1,inplace = True)
df['Sex'] = df['Sex'].fillna(df['Sex'].mode()[0])
df['Embarked'] = df['Embarked'].fillna(df['Embarked'].mode()[0])
df['Fare'] = df['Fare'].fillna(df['Fare'].median())
df['Fare'] = df['Fare'].fillna(df['Fare'].median())
df.isnull().sum()
plt.boxplot(df['Age'])
plt.show()
plt.boxplot(df['Fare'])
plt.show()
#handling outlier in fare
q1 = df['Fare'].quantile(0.25)
q3 = df['Fare'].quantile(0.75)
iqr = q3 - q1
lower = q1 - 1.5 * iqr
upper = q3 + 1.5 * iqr
df['Fare'] = np.clip(df['Fare'],lower,upper)
#remove unwanted columns
df.drop('PassengerId',axis = 1, inplace = True)
df.drop('Name',axis = 1, inplace = True)
df.drop('Ticket',axis = 1, inplace = True)
df.columns
df = pd.get_dummies(df,columns = ['Sex','Embarked'])
df.dtypes
df.tail()
df.drop(1308,inplace = True)
matrix = df.corr()
matrix
sns.heatmap(matrix,annot = True)
plt.show()
df['column_name'].replace(calue_to_replace, np.nan, inplace=
True)