Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

label encoding of a column in python

import seaborn as sns 
df = sns.load_dataset('iris')
def encode(x):
    for i,j in enumerate(df['species'].unique()):
        if x == j:
            return i

df['species'] = df['species'].apply(lambda x:encode(x))
Comment

PREVIOUS NEXT
Code Example
Python :: python array spread 
Python :: print function python 
Python :: python iterate through list 
Python :: how to generate two random numbers in python 
Python :: add in python 
Python :: Dependency on app with no migrations: 
Python :: diccionario python 
Python :: how to represent equation in pytho 
Python :: python how to make a user input function 
Python :: code optimization in python 
Python :: google oauth python tutorial 
Python :: number data type in python 
Python :: numpy nditer 
Python :: how to add keyboard to python turtle 
Python :: get more than one decimal in python 
Python :: pyglet on button press 
Python :: simple plt plot 
Python :: starry spheres 
Python :: how to make hidden folders python 
Python :: python beautifulsoup load cookies download file from url 
Python :: is cobol obsolete 
Python :: Highlighting the shortest path in a Networkx graph 
Shell :: chrome remote debug 
Shell :: emu8086 registration key 
Shell :: the windows subsystem for linux component is not enabled 
Shell :: find gnome shell version 
Shell :: date linux format yyyymmdd 
Shell :: update composer ubuntu 
Shell :: flush dns cmd 
Shell :: write a bash program to print a given number in reverse order 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =