Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please provide python code to perform one hot encoding for below 6 categorical variables in dataset df cat = ['Location_type', 'WH_capacity_size', 'zone', 'WH_regional_zone', 'wh_owner_type', 'approved_wh_govt_certificate']

Please provide python code to perform one hot encoding for below 6 categorical variables in dataset df

cat = ['Location_type', 'WH_capacity_size', 'zone', 'WH_regional_zone', 'wh_owner_type', 'approved_wh_govt_certificate']

#Replace Location_type Rural with 1 and Urban with 2
df['Location_type'] = df['Location_type'].replace({'Rural' : 1, 'Urban' :2})

#Replace WH_capacity_size Large with 2, Medium with 1 and Small with 0
df['WH_capacity_size'] = df['WH_capacity_size'].replace({'Large' :2, 'Mid' :1, 'Small' :0})

#Replace Zone East with 1, West with 2, North with 3 and South with 4
df['zone'] = df['zone'].replace({'East' : 1, 'West' :2, 'North' : 3, 'South' :4})

#Replace WH_regional_zone zone1 with 1, zone2 with 2,zone3 with 3,zone4 with 4 and zone5 with 5
df['WH_regional_zone'] = df['WH_regional_zone'].replace({'Zone 1' : 1, 'Zone 2' :2, 'Zone 3' :3, 'Zone 4' :4,'Zone 5' :5, 'Zone 6' :6})

#Replace wh_owner_type Company Owned with 1 and Rented with 2
df['wh_owner_type'] = df['wh_owner_type'].replace({'Company Owned' : 1, 'Rented' :2})

#Replace approved_wh_govt_certificate A+ with 5, A with 4, B+ with 3, B with 2, C with 1 and NA with 0
df['approved_wh_govt_certificate'] = df['approved_wh_govt_certificate'].replace({'A+' : 5, 'A' :4, 'B+' : 3, 'B' :2, 'C' : 1, 'NA' : 0})

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Statistics In Practice

Authors: Bruce Bowerman, Richard O'Connell

6th Edition

0073401838, 978-0073401836

More Books

Students also viewed these Algorithms questions

Question

What are streamlines?

Answered: 1 week ago

Question

Job type Retail sales, managerial, human resources, etc.

Answered: 1 week ago