# 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()
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'''
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))