Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

label encoding in pandas

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

label encoding column pandas

import seaborn as sns 
df = sns.load_dataset('iris')
df['species'] = df['species'].astype('category').cat.codes
df.head(3)
'''sepal_length	sepal_width	petal_length	petal_width	species
	5.1					3.5			1.4					0.2			0
	4.9					3.0			1.4					0.2			0
	4.7					3.2			1.3					0.2			0'''
Comment

PREVIOUS NEXT
Code Example
Python :: spacy stopwords 
Python :: f-string ponto decimal python 
Python :: python get ros package path 
Python :: filter with different operator in django 
Python :: matplotlib change font 
Python :: pygame fullscreen 
Python :: python import from other folder outside folder 
Python :: python matplotlib plot thickness 
Python :: import matplotlib.pyplot as plt 
Python :: df dropna ensure that one column is not nan 
Python :: save images cv2 
Python :: python merge pdfs 
Python :: how to get all links text from a website python beautifulsoup 
Python :: python requests.get timeout 
Python :: cv display image in full screen 
Python :: dataframe to list 
Python :: age in days to age in years 
Python :: converting a csv into python list 
Python :: how to find if a value is even or odd in python 
Python :: selenium page down key python 
Python :: get attribute in selenium python 
Python :: django raise 404 
Python :: Write a Python program to append text to a file and display the text. 
Python :: mp4 to mp3 in python 
Python :: size table python 
Python :: tkinter draw circle 
Python :: python months between two dates 
Python :: LookupError: unknown encoding: idna python 
Python :: how to subtract 2 lists in python 
Python :: python get args 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =