Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

convert categorical data type to int in pandas

from sklearn import preprocessing

lab_encoder = preprocessing.LabelEncoder()
df['column'] = lab_encoder.fit_transform(df['column'])
Comment

panda categorical data into numerica

sex = train_dataset['Sex'].replace(['female','male'],[0,1])
print(sex)
Comment

pandas categorical to numeric

#this will label as one hot vectors (origin is split into 3 columns - USA, Europe, Japan and any one place will be 1 while the others are 0)
dataset['Origin'] = dataset['Origin'].map({1: 'USA', 2: 'Europe', 3: 'Japan'})
Comment

PREVIOUS NEXT
Code Example
Python :: swagger library for django 
Python :: gematria python 
Python :: flatten columns after pivot pandas 
Python :: python list all methods of a class 
Python :: cartesian product pandas 
Python :: pyplot new figure 
Python :: how to iterate through a list in python 
Python :: remove keys from array python 
Python :: python named group regex example 
Python :: how to install packages inside thepython script 
Python :: run django localhost server 
Python :: python extract specific keys from dictionary 
Python :: how to make a column a factor in pandas 
Python :: convert timedelta to int 
Python :: pathlib remove extension 
Python :: merge subplot matplotlib 
Python :: How to convert string date to datetime format in python 
Python :: how to get confusion matrix in python 
Python :: suppress python vs try/except pass 
Python :: how to code python 
Python :: how to access dataframe row by datetime index 
Python :: changing the port of django port 
Python :: how to check if item is in the variable python 
Python :: code for python shell 3.8.5 games 
Python :: install a lower version of python using conda 
Python :: how to check if an element is in a list python 
Python :: remove dot from number python 
Python :: how to power in python 
Python :: Python, importing other scripts from other directories 
Python :: data normalization python 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =