Encodage d'étiquette d'une colonne en 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))
pythonized