Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

label encoder python

from sklearn.preprocessing import LabelEncoder
encoder = LabelEncoder()

# apply on df
df['status'] = encoder.fit_transform(df['status'])
# can allso use the pandas.map
df['status'] = df['status'].map(lambda x: 1 if x=='Placed' else 0)

#apply on np.array
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [1])], remainder='passthrough')
X = np.array(ct.fit_transform(X))
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 :: how to delete na values in a dataframe 
Python :: django user form 
Python :: verificar se arquivo existe python 
Python :: pandas convert index to column 
Python :: install curses python 
Python :: webbrowser python could not locate runnable browser 
Python :: pandas replace nonetype with empty string 
Python :: pandas groupby column count distinct values 
Python :: max of two columns pandas 
Python :: how to set learning rate in keras 
Python :: how to find the most frequent value in a column in pandas dataframe 
Python :: python time now other timezone 
Python :: python multiply list by scalar 
Python :: correlation between lists python 
Python :: how to open an external file in python 
Python :: how to install pygame in python 3.8 
Python :: supprimer fichier pythpn 
Python :: delete unnamed 0 columns 
Python :: thousands separator python 
Python :: docker compose command not found 
Python :: fibonacci series python recursion 
Python :: favicon django 
Python :: how to use rmse as loss function in keras 
Python :: reverse dictionary python 
Python :: mongodb between two values 
Python :: pyautogui keyboard write 
Python :: py get days until date 
Python :: remove nan from list python 
Python :: tkinter max size 
Python :: pandas dataframe convert nan to string 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =