Difference between revisions of "Panda: Scaling Select Colums"

From OnnoWiki
Jump to navigation Jump to search
(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,...")
 
 
Line 19: Line 19:
 
  scaled_df = scaleColumns(dfTest,['A','B'])
 
  scaled_df = scaleColumns(dfTest,['A','B'])
 
  print scaled_df
 
  print scaled_df
 +
 +
 +
 +
==Pranala Menarik==
 +
 +
* [[Python]]

Latest revision as of 09:46, 9 August 2019



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