Q8.webp
lanthao2000

Q8.webp

Kizspy | Question: 8
(Choose 1 answer)
You have the following DataFrame df:
import pandas as pd
df pd.DataFrame({
})
'Color': ['Red', 'Blue', 'Green', 'Red', 'Blue', 'Green', 'Red']
Which code snippet correctly applies label encoding to the Color column, resulting in the unique values
{'Green': 2, 'Red': 0, 'Blue': 1, }?
A. df['Color_encoded"]=df['Color'].map({'Red': 0, 'Blue': 1, 'Green': 2})
B. from sklearn.preprocessing import LabelEncoder
le LabelEncoder()
df['Color_encoded'] = le.fit_transform(df['Color'])
C. df['Color_encoded"]=df['Color'].apply(lambda x: {'Red': 2, 'Blue': 0, 'Green': 1}[x])
D. df['Color_encoded"]=df['Color'].astype('category').cat.codes

Thông tin

Category
DAP391m
Thêm bởi
lanthao2000
Ngày thêm
Lượt xem
1,047
Lượt bình luận
5
Rating
0.00 star(s) 0 đánh giá

Share this media

Back
Bên trên Bottom