Panda: Scaling Select Colums

From OnnoWiki
Revision as of 09:46, 9 August 2019 by Onnowpurbo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search



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


Pranala Menarik