Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python function to scale selected features in a dataframe pandas

# make a copy of dataframe
scaled_features = df.copy()

col_names = ['co_1', 'col_2', 'col_3', 'col_4']
features = scaled_features[col_names]

# Use scaler of choice; here Standard scaler is used
scaler = StandardScaler().fit(features.values)
features = scaler.transform(features.values)

scaled_features[col_names] = features
Comment

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
Comment

PREVIOUS NEXT
Code Example
Python :: length of pandas dataframe 
Python :: loop through python object 
Python :: python nth prime function 
Python :: matlab to python 
Python :: set index in datarame 
Python :: count frequency of characters in string 
Python :: duplicate data in python 
Python :: python file reading 
Python :: program for factorial of a number in python 
Python :: delete certain characters from a string python 
Python :: list python virtual environments 
Python :: list to string 
Python :: iso date convert in python 
Python :: sha512 python 
Python :: python count empty lines in text file 
Python :: numpy arrauy to df 
Python :: python remove whitespace from start of string 
Python :: pymongo [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate 
Python :: python insertion sort 
Python :: replace string if it contains a substring pandas 
Python :: how to urllib3 
Python :: np.polyfit plot 
Python :: ping with python 
Python :: convert float in datetime python 
Python :: streamlit change tab name 
Python :: python spotify player 
Python :: read binary image python 
Python :: batchnorm1d pytorch 
Python :: delete migrations django and start over deployment heroku 
Python :: count of datatypes in columns 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =