normalize data python pandas
import pandas as pd from sklearn import preprocessing x = df.values #returns a numpy array min_max_scaler = preprocessing.MinMaxScaler() x_scaled = min_max_scaler.fit_transform(x) df = pd.DataFrame(x_scaled)
normalize data python pandas
import pandas as pd from sklearn import preprocessing x = df.values #returns a numpy array min_max_scaler = preprocessing.MinMaxScaler() x_scaled = min_max_scaler.fit_transform(x) df = pd.DataFrame(x_scaled)
standardize columns in pandas
columns = ['A', 'B','C'] #specify the column names for col in columns: df[col] = (df[col] - df[col].mean())/df[col].std()
function to scale features in dataframe
# define a method to scale data, looping thru the columns, and passing a scaler def scale_data(data, columns, scaler): for col in columns: data[col] = scaler.fit_transform(data[col].values.reshape(-1, 1)) return data
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us