Exercise

Discretizing all variables

Instead of discretizing the continuous variables one by one, it is easier to discretize them automatically. To get a list of all the columns in Python, you can use

variables  = basetable.columns

Only variables that are continuous should be discretized. You can verify whether variables should be discretized by checking whether they have more than a predefined number of different values.

Instructions

100 XP
  • Make a list variables containing all the column names of the basetable.
  • Create a loop that checks all the variables in the list variables.
  • Complete the ifstatement such that only variables with more than 5 different values are discretized.
  • Group the continuous variables in 10 bins using the qcut method.