import pandas as pd
df = pd.DataFrame({
'A':['a', 'b', 'c', 'a', 'b'],
'B':[1,2,3,1,0]
})
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
le.fit(df['A'])
le.transform(['a','b']) # array([0, 1])
le.inverse_transform([1,2,2,2]) # array(['b', 'c', 'c', 'c'], dtype=object)
# fit-transform 한 번에 진행
le.fit_transform(df['A'])
from sklearn.preprocessing import MinMaxScaler
mms = MinMaxScaler()
# fit
mms.fit(df)
# transform
df_mms = mms.transform(df)
# 역변환
mms.inverse_transform(df_mms)
# 한 번에
mms.fit_transform(df)
from sklearn.preprocessing import StandardScaler
ss = StandardScaler()
ss.fit(df)
df_ss = ss.transform(df)
ss.inverse_transform(df_ss)
ss.fit_transform(df)
from sklearn.preprocessing import RobustScaler
rs = RobustScaler()
df_rs = rs.fit_transform(df)
Reference
1) 데이터스쿨 강의자료