Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Handling categorical feature

## 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 :: extract all text from website using beautifulsoup and python 
Python :: filter a pandas dataframe by length of list in a column 
Python :: how to redirect in django 
Python :: how to reindex columns in pandas 
Python :: read data from s3 bucket python 
Python :: Pandas: How to Drop Rows that Contain a Specific String in 2 columns 
Python :: url encoded path using python 
Python :: sum of list in python 
Python :: compose functions python 
Python :: python dictionary 
Python :: rps python 
Python :: ERROR: Command errored out with exit status 1 
Python :: python memory usage 
Python :: plot title overlapping yaxis python 
Python :: install python in dockerfile 
Python :: how to use pip commands in pycharm 
Python :: sort in python 
Python :: even numbers from 1 to 100 in python 
Python :: taking array input in python 
Python :: python string to list of int 
Python :: count nan values 
Python :: python get local ipv4 
Python :: fibonacci series using dynamic programmig approach 
Python :: python thread stop 
Python :: python convert int to hex string 
Python :: python list Clear the list content 
Python :: Iterate through string backwards in python 
Python :: python defaultdict to dict 
Python :: delete rows in a table that are present in another table pandas 
Python :: python turtle fill 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =