Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

label encoder python

from sklearn.preprocessing import LabelEncoder
encoder = LabelEncoder()

# apply on df
df['status'] = encoder.fit_transform(df['status'])
# can allso use the pandas.map
df['status'] = df['status'].map(lambda x: 1 if x=='Placed' else 0)

#apply on np.array
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [1])], remainder='passthrough')
X = np.array(ct.fit_transform(X))
 
PREVIOUS NEXT
Tagged: #label #encoder #python
ADD COMMENT
Topic
Name
6+7 =