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

how to convert categorical data to numerical data in python

pd.get_dummies(obj_df, columns=["body_style", "drive_wheels"], prefix=["body", "drive"]).head()
Comment

how to convert categorical data to numerical data in python

obj_df["body_style"] = obj_df["body_style"].astype('category')
obj_df.dtypes
Comment

PREVIOUS NEXT
Code Example
Python :: give answer in 6 decimal python 
Python :: python remove nan rows 
Python :: small factorial codechef solution 
Python :: model o weight 
Python :: how to do element wise multiplication in numpy 
Python :: connection to server at "" (), port 5432 failed: timeout expired 
Python :: python django shell command 
Python :: python open file 
Python :: python add all items in list 
Python :: erase % sign in row pandas 
Python :: how to draw a rectangle in pygame 
Python :: python copy an object 
Python :: spacy load en 
Python :: convert string to list of dictionaries 
Python :: 2 variables with statement python 
Python :: add age categories pandas dataframe 
Python :: convert data type object to string python 
Python :: download images python google 
Python :: Inconsistent use of tabs and spaces in indentationPylance 
Python :: own labels for ticks matplotlib 
Python :: dataframe pandas to spark 
Python :: python list empty 
Python :: how to install from url in python 
Python :: python for loop even numbers 
Python :: np confidence interval 
Python :: convert pandas dataframe/ table to python dictionary 
Python :: python count number of unique elements in a list 
Python :: true positive true negative manually 
Python :: python list slicing 
Python :: python get attributes of class 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =