Answers for "label encoding of a column in python"

0

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))
Posted by: Guest on September-08-2021

Python Answers by Framework

Browse Popular Code Answers by Language