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 :: python loop dictionary 
Python :: python docstring use 
Python :: python wsgi 
Python :: pd.explode 
Python :: python group by 
Python :: python string: .replace() 
Python :: Python program to calculate area of a rectangle using function 
Python :: delete function python 
Python :: global python 
Python :: how to read mysql table in python 
Python :: a python string 
Python :: np minimum of array 
Python :: creating an object in python 
Python :: sum of diagonal numpy 
Python :: lists in python 
Python :: add key value in each dictonary in the list 
Python :: how to remove trailing zeros in python 
Python :: python else syntax 
Python :: pyqt5 buttons 
Python :: how to use iteration in python 
Python :: parce que in english 
Python :: how to create a save command in python 
Python :: python sort case insensitive 
Python :: how to convert uppercase to lowercase and vice versa in python 
Python :: how to swap numbers in python mathematically 
Python :: python builtwith 
Python :: TypeError: cannot unpack non-iterable float object evaluate 
Python :: Python Switch case statement Using classes 
Python :: hwo to syntax in python 
Python :: utils/decorators.py", line 11, in __get__ raise AttributeError("This method is available only on the class, not on instances.") AttributeError: This method is available only on the class, not on instances. 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =