December 2018
Beginner to intermediate
684 pages
21h 9m
English
We need to convert the categorical stock variable into a numeric format so that the linear regression can process it. For this purpose, we use dummy encoding that creates individual columns for each category level and flags the presence of this level in the original categorical column with an entry of 1, and 0 otherwise. The pandas function get_dummies() automates dummy encoding. It detects and properly converts columns of type objects as illustrated next. If you need dummy variables for columns containing integers, for instance, you can identify them using the keyword columns:
df = pd.DataFrame({'categories': ['A','B', 'C']}) categories0 A1 B2 Cpd.get_dummies(df) categories_A categories_B categories_C ...