Creating new variables
A dataset is not only the data you see. There is a lot of information in it. For example, remember in Chapter 6, when we worked with datetime objects during our data exploration exercise, we took the TIME
variable and extracted the year, month, day, and hour from it. This is one of the many ways to create new variables.
Here are some examples of new variables created out of our working dataset:
- Arithmetical operators: Adding two or more variables to create a
total
variable. - Text extraction: Extracting a meaningful part of a text, for instance,
1234
fromORDER-1234
. - Custom calculations: Calculating a discount rate based on a business rule.
- Binarization: Transforming a variable from
on
andoff
to1
and0
. Binary means two options and is commonly associated with0
and1
in computer language. - Encoding: Transforming a qualitative ordinal variable, such as
basic
,intermediate
, andadvanced
to1
,2
, and3
. - One Hot Encoding: A very common...