google 数据科学手册中 google 股票价格示例的 Matplotlib

Matplotlib for google stock price example in python data science handbook

使用 Python 数据科学手册(第 198 页图 3.6 为来自 google 的任何人重新采样和转换频率),我正在尝试按照示例进行操作,如下所示:

%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');

我的图表如下所示:

示例如下所示:

为什么会这样?我很确定代码是完全相同的。我该如何解决这个问题?

没有什么不对的,只是重采样规则BAmean()returns只有两个点,因此是直线。

玩不同的 available offset rules 我无法快速重现所需的情节。您应该尝试探索和使用可能是几天的倍数。