To proceed with the recipe, let's import the libraries and create a toy dataset:
- Import pandas and NumPy:
import numpy as npimport pandas as pd
- Let's create 20 datetime values, beginning from 2019-03-05 at midnight followed by increments of 1 month. Then, let's capture the value range in a dataframe and display the top five rows:
rng_ = pd.date_range('2019-03-05', periods=20, freq='M')df = pd.DataFrame({'date': rng_}) df.head()
Note how the values increase by one month in the first five observations of the variable we created:
- Let's extract the year part of the date in a new column and display the top five rows of the ...