Create a DatetimeIndex that contains each business day of 2015 and use it to index a Series of random numbers. Let's…
PythonLevel: Intermediate
Create a DatetimeIndex that contains each business day of 2015 and use it to index a Series of random numbers. Let's call this Series s.
Assume import pandas as pd and import numpy as np.
Hints
- First define row granularity, column types and keys.
- Check index alignment, missing values and output size after the transformation.
Answer
dti = pd.date_range(start='2015-01-01', end='2015-12-31', freq='B')
s = pd.Series(np.random.rand(len(dti)), index=dti)
s
Source and licence: 100 pandas puzzles — Alex Riley and contributors · MIT