Skip to content

Instantly share code, notes, and snippets.

@AyishaR
Created February 13, 2021 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AyishaR/4661df978ff4a7731a488f539b0ddab4 to your computer and use it in GitHub Desktop.
Save AyishaR/4661df978ff4a7731a488f539b0ddab4 to your computer and use it in GitHub Desktop.
# 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