Panda: Scaling Select Colums
Revision as of 09:45, 9 August 2019 by Onnowpurbo (talk | contribs) (Created page with " import pandas as pd import numpy as np from sklearn import preprocessing dfTest = pd.DataFrame({'A':[14.00,90.20,90.95,96.27,91.21],'B':[103.02,107.26,110.35,114.23,...")
import pandas as pd import numpy as np from sklearn import preprocessing dfTest = pd.DataFrame({'A':[14.00,90.20,90.95,96.27,91.21],'B':[103.02,107.26,110.35,114.23,114.68], 'C':['big','small','big','small','small']}) min_max_scaler = preprocessing.MinMaxScaler() def scaleColumns(df, cols_to_scale): for col in cols_to_scale: df[col] = pd.DataFrame(min_max_scaler.fit_transform(pd.DataFrame(dfTest[col])),columns=[col]) return df print dfTest scaled_df = scaleColumns(dfTest,['A','B']) print scaled_df