April 2019
Intermediate to advanced
426 pages
11h 13m
English
We have already downloaded the JPM dataset to the pandas DataFrame, df_jpm, in a previous section, and the y variable contains the daily percentage change of JPM. Convert these values to labels with the following code:
In [ ]: import numpy as np y_direction = y >= 0 y_direction.head(3)Out[ ]: date
1998-01-05 True
1998-01-06 False
1998-01-07 True Name: 5. adjusted close, dtype: bool
Using the head() command, we can see that the y_direction variable becomes a pandas Series object of Boolean values. A percentage change of zero or more classifies the value with a True label, and False otherwise. Let's extract unique values with the unique() command as column names for use later on:
In [ ]: flags = list(y_direction.unique()) ...
Read now
Unlock full access