import pandas as pd
from sklearn.preprocessing import LabelEncoder
data={
'student':["deva","shankar","vamshi","barath","sohel"],
'score':[100,90,80,67,96],
'passorfail':["yes","yes","yes","no","yes"]
}
df=pd.DataFrame(data)
print(df)
label_encoder=LabelEncoder()
df=pd.DataFrame(data)
df['col_encoder']=label_encoder.fit_transform(df['passorfail'])
print(df)
/*output
student score passorfail col_encoder
0 deva 100 yes 1
1 shankar 90 yes 1
2 vamshi 80 yes 1
3 bara 67 no 0
4 sohel 96 yes 1*/
Preview:
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