Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Using mapping in Converting categorical feature in to numerical features

## Converting range of Age to numeric variable using (target ordinary encodiing)
## Note: Dont map from 0 because of mathematical issue, you should always satart your mapping from 1


df['Age']=df['Age'].map({'0-17':1, 
                         '18-25':2, 
                         '26-35':3, 
                         '36-45':4, 
                         '46-50':5, 
                         '51-55':6, 
                         '55+':7  })
df.head()

#or

## Converting Gender "M" and "F" to numeric variable
## Note: Dont map from 0 because of mathematical issue, you should always satart your mapping from 1

df['Gender']=df['Gender'].map({'F':0, 'M':1})
df.head()
Comment

PREVIOUS NEXT
Code Example
Python :: mode with group by in python 
Python :: using a dictionary in python 
Python :: selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: 
Python :: type de variable python 
Python :: concardinate str and a variable in python 
Python :: how to install python pyautogui 
Python :: how to enter a int in python 
Python :: pi in python 
Python :: numpy declare arraylength 
Python :: how to use random tree in python 
Python :: python game 
Python :: python file to array 
Python :: python datetime get date one week from today 
Python :: opencv loop video 
Python :: python join dict 
Python :: render django template 
Python :: how to make python open an application on mac 
Python :: select multiple dict 
Python :: python string trim 
Python :: python .nlargest 
Python :: heroku requirements.txt python 
Python :: local ip 
Python :: python define class 
Python :: append extend python 
Python :: python argv 
Python :: initialize a 2d list python 
Python :: all() python 
Python :: concatenate list of strings python 
Python :: Python NumPy broadcast_arrays() Function Example 
Python :: pandas convert string column to int list column 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =