由于要分析Google的历史股票价格数据进行可视化,导入了Pandas_datareader程序包
pip install pandas_datareader
导入数据:
from pandas_datareader import data
goog=data.DataReader('GOOG',start='2004',end='2016',data_source='google')
print(goog.head())
报错,出现以下问题:
Traceback (most recent call last):
File "E:/python数据/goole-finance.py", line 2, in
goog=data.DataReader('GOOG',start='2004',end='2016',data_source='google')
File "D:\python3.6.5\lib\site-packages\pandas_datareader\data.py", line 316, in DataReader
session=session).read()
File "D:\python3.6.5\lib\site-packages\pandas_datareader\google\daily.py", line 36, in __init__
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Google finance'))
pandas_datareader.exceptions.ImmediateDeprecationError:
Google finance has been immediately deprecated due to large breaks in the API without the
introduction of a stable replacement. Pull Requests to re-enable these data
connectors are welcome.
See https://github.com/pydata/pandas-datareader/issues
Process finished with exit code 1
查找原因,说是还要引用一个库fix-yahoo-finance,直接pip安装
pip install fix-yahoo-finance
cmd出现错误:
后来在pypi下载离线安装包,依然存在这个问题,直到无意看到这个:
意思就是说,这个包改名了,你要用yfinance这个名字。。。。。。(论英语的重要性==)
pip install yfinance
终于搞定!没有报错了
参考另外两位博客:
https://blog.csdn.net/Hellolijunshy/article/details/82527643
https://blog.csdn.net/qq_24974989/article/details/82875029
运行代码:
import pandas_datareader.data as web
import yfinance as yf
import datetime
yf.pdr_override()
start=datetime.datetime(2004,8,19)
end=datetime.datetime(2012,1,1)
apple=web.get_data_yahoo('GOOGL',start,end)
print(apple.head())
运行结果:
D:\python3.6.5\python.exe E:/python数据/goole-finance.py
[*********************100%***********************] 1 of 1 downloaded
Open High Low Close Adj Close Volume
Date
2004-08-19 50.05 52.08 48.03 50.22 50.22 44659000
2004-08-20 50.56 54.59 50.30 54.21 54.21 22834300
2004-08-23 55.43 56.80 54.58 54.75 54.75 18256100
2004-08-24 55.68 55.86 51.84 52.49 52.49 15247300
2004-08-25 52.53 54.05 51.99 53.05 53.05 9188600
Process finished with exit code 0