Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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 :: Check if the url is reachable or not in Python 
Python :: python check samplerate of mp3 
Python :: python uppercase 
Python :: increment in python 
Python :: python dictionary to list 
Python :: if string is in array python 
Python :: np.stack 
Python :: datetime.time to seconds 
Python :: json and python login system 
Python :: Python of add two numbers 
Python :: python game example 
Python :: save screenshot of screen in pygame 
Python :: memory usage in python 
Python :: pandas change period to daily frequency 
Python :: how to print a string in python 
Python :: remove rows from pandas 
Python :: how to install docx in python 
Python :: fullscreen cmd with python 
Python :: resample ohlc pandas 
Python :: python get array length 
Python :: django annotate vs aggregate 
Python :: get local ipv4 
Python :: max int python 
Python :: find all occurrences of an element in a list python 
Python :: python callable type hint 
Python :: how to clear the list in python 
Python :: python split list 
Python :: python dict remove duplicates where name are not the same 
Python :: python crop string 
Python :: range(len()) in python 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =