1. use pandas
import numpy as np
""" coverted string class to integer """
class-map = { label : idx for idx, label in enumerate(np.unique(df['class']))}
""" reversed integer to strings """
df['class'] = df['class'].map(class-map)
2. use scikit-learn
from sklearn.preprocessing import LabelEncoder
enc = LabelEncoder()
""" converted integer to strings """"
y = enc.fit_transform(df['class'].values)
""" reversed integer to strings """
enc.inverse_transform(y)
'데이터분석 > pandas' 카테고리의 다른 글
imputing missing values in pandas (0) | 2023.07.03 |
---|---|
drop missing data in dataframe (0) | 2023.07.03 |
data cleaning (0) | 2019.11.06 |
nump 사용 (0) | 2019.10.31 |
data crawling (0) | 2019.10.28 |