Preview:
from sklearn.preprocessing import OrdinalEncoder

data = {'Size': ['Small', 'Medium', 'Large', 'Medium']}
df = pd.DataFrame(data)

encoder = OrdinalEncoder(categories=[['Small', 'Medium', 'Large']])

df['Size_encoded'] = encoder.fit_transform(df[['Size']])
print(df)
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter