1. Learn
  2. /
  3. Courses
  4. /
  5. Feature Engineering with PySpark

Exercise

Scaling your scalers

In the previous exercise, we minmax scaled a single variable. Suppose you have a LOT of variables to scale, you don't want hundreds of lines to code for each. Let's expand on the previous exercise and make it a function.

Instructions

100 XP
  • Define a function called min_max_scaler that takes parameters df a dataframe and cols_to_scale the list of columns to scale.
  • Use a for loop to iterate through each column in the list and minmax scale them.
  • Return the dataframe df with the new columns added.
  • Apply the function min_max_scaler() on df and the list of columns cols_to_scale.