Using the Python data science handbook (pg.198 Fig 3.6 resampling and converting frequencies for anyone from google), I'm trying to follow the example, which is as below:
%matplotlib inline
import pandas as pd
import numpy as np
from pandas_datareader import data
import matplotlib.pyplot as plt
import seaborn; seaborn.set()
goog = data.DataReader('GOOG', start='2004', end='2016',
data_source='google')
goog = goog['Close']
goog.plot(alpha=0.5, style='-')
goog.resample('BA').mean().plot(style=':')
goog.asfreq('BA').plot(style='--');
plt.legend(['input', 'resample', 'asfreq'],
loc='upper left');
While the example look like this:
Why is this the case? I'm pretty certain that the code is an exact duplicate. How can I solve this issue?
There is nothing really wrong, just that the resampling rule BA
with mean()
returns only two points, thus the straight line.
Playing with the different available offset rules I don't manage to quickly reproduce the desired plot. You should try to explore and use perhaps a multiple of days.