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

# 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

function to scale features in dataframe

Similar Code Examples