-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpreprocessing.py
37 lines (31 loc) · 1.83 KB
/
preprocessing.py
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
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
import warnings
warnings.filterwarnings('ignore')
def preprocess(df, option):
#Drop values based on operational options
if (option == "Online"):
df['location_type'] = le.fit_transform(df['location_type'])
df['cellphone_access'] = le.fit_transform(df['cellphone_access'])
df['gender_of_respondent'] = le.fit_transform(df['gender_of_respondent'])
df['relationship_with_head'] = le.fit_transform(df['relationship_with_head'])
df['education_level'] = le.fit_transform(df['education_level'])
df['marital_status'] = le.fit_transform(df['marital_status'])
df['job_type'] = le.fit_transform(df['job_type'])
elif (option == "Batch"):
pass
df = df[['location_type', 'cellphone_access', 'household_size','age_of_respondent', 'gender_of_respondent', 'relationship_with_head','marital_status', 'education_level', 'job_type']]
# columns = ['location_type', 'cellphone_access','gender_of_respondent', 'relationship_with_head','marital_status', 'education_level', 'job_type']
#covertion
df['location_type'] = le.fit_transform(df['location_type'])
df['cellphone_access'] = le.fit_transform(df['cellphone_access'])
df['gender_of_respondent'] = le.fit_transform(df['gender_of_respondent'])
df['relationship_with_head'] = le.fit_transform(df['relationship_with_head'])
df['education_level'] = le.fit_transform(df['education_level'])
df['marital_status'] = le.fit_transform(df['marital_status'])
df['job_type'] = le.fit_transform(df['job_type'])
else: #Encoding the other categorical categoric features with more than two categories
print("Incorrect operational options")
return df