import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
start = dt.datetime (2000,1,1)
end = dt.datetime (2018,1,1)
df=web.DataReader('TSLA', 'morningstar', start, end)
print(df.head())
尝试使用以上代码,但出现错误:
File "/anaconda3/lib/python3.6/site-packages/pandas_datareader/compat/__init__.py", line 8, in <module>
import pandas.io.common as com
AttributeError: module 'pandas.io' has no attribute 'common'
答案 0 :(得分:0)
问题出在您的python环境中,而不是代码。
当我在环境Python 3.6.4
上运行您的代码时,您的代码将产生以下输出。
Close High Low Open Volume
Symbol Date
TSLA 2010-06-29 23.9 25.0 17.5 19.0 18783276
2010-06-30 23.8 30.4 23.3 26.0 17194394
2010-07-01 22.0 25.9 20.3 25.0 8216789
2010-07-02 19.2 23.1 18.7 23.0 5135795
2010-07-05 19.2 19.2 19.2 19.2 0
您将需要升级环境,请在终端上发出以下命令,然后重新启动python环境。
pip install --upgrade pip
pip install pandas-datareader