-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabular_data_manipulation.py
More file actions
87 lines (48 loc) · 1.23 KB
/
Copy pathtabular_data_manipulation.py
File metadata and controls
87 lines (48 loc) · 1.23 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
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
"""Tabular_Data_Manipulation.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/16YuGzENJQKopi0oVHYcN9NTamOLhXWYJ
"""
import pandas as pd
df = pd.read_csv("/content/titanic.csv")
df.head(3)
df.tail()
df.shape
df.info()
df.describe()
df.head()
"""# handlilng Categorical features"""
df =df.drop('Name', axis = 1)
df
df = df.drop('Ticket', axis = 1)
df = df.drop('Cabin', axis = 1)
df
df['Sex'].nunique()
df['Sex'].unique()
df['Embarked'].unique()
df['Embarked'] = df['Embarked'].map({'S':0, 'C':1, 'Q':2})
df.head()
df['Embarked'].unique()
df['Sex'] =df['Sex'].map({'male':0, 'female':1})
df.head()
"""# hadling null values"""
df.info()
df['Embarked'].isnull().sum()
df['Embarked'] = df['Embarked'].fillna(0)
df.info()
df.describe()
df['Age'] = df['Age'].fillna(29)
df.info()
df.duplicated().sum()
import seaborn as sns
import matplotlib.pyplot as plt
sns.boxplot(x = df['Fare'])
plt.show()
"""# NOrmalization and standardization"""
from sklearn.preprocessing import MinMaxScaler, StandardScaler
NN = MinMaxScaler()
SD = StandardScaler()
df['Age'] = NN.fit_transform(df[['Age']])
df['Fare'] = SD.fit_transform(df[['Fare']])
df.head()