Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Converting categorical feature in to numerical features using target ordinary encoding

## 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 :: python how to see what pip packages are installed 
Python :: input pythhon 
Python :: how to call a random function in python 
Python :: trim string python 
Python :: # decorator 
Python :: __delattr__ python 
Python :: python if and 
Python :: next() python 
Python :: python json random number generator 
Python :: pandas drop missing values for any column 
Python :: python example 
Python :: python remove empty values from list 
Python :: make poetry env 
Python :: python get the intersection of two lists 
Python :: find value in dictionary python 
Python :: How to get the first and last values from the dataframe column using a function 
Python :: pandas concat 
Python :: one hot numpy 
Python :: Python Tkinter Text Widget Syntax 
Python :: python uuid 
Python :: python check if string in string 
Python :: get local ip 
Python :: how to make a game in python 
Python :: random python range 
Python :: python generate pdf from template 
Python :: how to make a clock in python 3 
Python :: django meta attributes 
Python :: python dict remove duplicates where items are not the same 
Python :: get country from city python 
Python :: os chdir python 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =