Created
February 13, 2021 11:56
-
-
Save AyishaR/4661df978ff4a7731a488f539b0ddab4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert binary to int | |
df['Weekend'] = df['Weekend'].astype('int64') | |
df['Revenue'] = df['Revenue'].astype('int64') | |
# One hot encoding | |
dummy_columns = ['OperatingSystems','Browser','Region','TrafficType','VisitorType'] | |
for column in dummy_columns: | |
df_dummies = pd.get_dummies(df[column], drop_first = True, prefix = column+"_") | |
df = pd.concat([df, df_dummies], axis = 1) | |
df = df.drop(columns = dummy_columns) | |
# Accounting for all months in the calendar | |
months = ['Jan','Feb','Mar','Apr','May','June','Jul','Aug','Sep','Oct','Nov','Dec'] | |
for mx in months[1:]: # drop_first = True | |
df[mx] = (df['Month'] == mx).astype('int64') | |
df = df.drop(columns = ['Month']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment