I have the below code:
var_list = ['a', 'b', 'c', 'd', 'd', 'e', 'f', 'g', 'h', 'i']
y_var = 'lp'
for x_var in var_list:
formula = y_var + ' ~ ' + x_var
results = smf.ols(formula, data=df).fit()
I would like to standardize the variables in the list and re-configure my loop to use the standardized variables instead.
I don't have any code of my own. I searched a bit and found the following code https://medium.com/@rrfd/standardize-or-normalize-examples-in-python-e3f174b65dfc which does the transformation:
from sklearn import preprocessing
import numpy as np
# Get dataset
df = pd.read_csv("https://storage.googleapis.com/mledudatasets/california_housing_train.csv", sep=",")# Normalize total_bedrooms column
# Create the Scaler object
scaler = preprocessing.StandardScaler()
# Fit your data on the scaler object
scaled_df = scaler.fit_transform(df)
scaled_df = pd.DataFrame(scaled_df, columns=names)