Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

label encoding

from sklearn.preprocessing import LabelEncoder

le = LabelEncoder()
companydata.ShelveLoc = le.fit_transform(companydata.ShelveLoc)
Comment

Label Encoding in python

##We apply Label Encoding on black Friday dataset on the target column which is Species. It contains three species Iris-setosa, Iris-versicolor, Iris-virginica. 

# Import libraries
import numpy as np
import pandas as pd
 
# Importing dataset
df = pd.read_csv('../../data/blackFriday.csv')

#Cheking out the unique values in your dataset
df['Age'].unique()

# Import label encoder
from sklearn import preprocessing
 
# label_encoder object knows how to understand word labels.
label_encoder = preprocessing.LabelEncoder()
 
# Encode labels in column 'Age'.
df['Age']= label_encoder.fit_transform(df['Age'])
 
df['Age'].unique()
Comment

PREVIOUS NEXT
Code Example
Python :: python style console output 
Python :: pyhton regex to find string in file 
Python :: convert from 12 hrs to 24 python 
Python :: invert a dictionary python 
Python :: python how to open a file in a different directory in mac 
Python :: how to make it so we can give unlimited parameters in python function 
Python :: pandas create new column and fill with constant value 
Python :: django post request 403 forbidden 
Python :: initialize dictionary with empty lists 
Python :: python delete folder and contents 
Python :: read live video from usb opencv python 
Python :: python check if exe is running 
Python :: python print in one line 
Python :: enumerate python 
Python :: django add model 
Python :: ipywidegtes dropdown 
Python :: rename column pandas 
Python :: python if else one line 
Python :: how to get something from a certian possition in a list python 
Python :: post request in python flaks 
Python :: python procedured 
Python :: remove particular row number in pandas 
Python :: remove special characters from string python 
Python :: datetime to unix timestamp milliseconds python 
Python :: ip regex python 
Python :: convert string to utf8 python 
Python :: difference between 2 timestamps pandas 
Python :: ipython.display install 
Python :: pandas str is in list 
Python :: dir template 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =