使用的《python for data analysis》版本是2014年版。
在本书P145,展示了一个使用dataframe计算相关系数和协方差的例子,里边涉及一个名为pandas.io.data的库,以及对应的get_data_yahoo方法。实测代码无法运行。具体变化如下:
-
库名从pandas.io.data更改为pandas_datareader,即import语句要对应改成
import pandas_datareader.data as xxx或者 import pandas_datareader.web as xxx
-
关注api接口的情况,部分摘录在下(原文请去https://pandas-datareader.readthedocs.io/en/latest/remote_data.html)
-
Yahoo! Finance has been immediately deprecated. Yahoo! substantially altered their API in late 2017 and the csv endpoint was retired.
-
Google’a API has become less reliable during 2017. While the google datareader often works as expected, it is not uncommon to experience a range of errors when attempting to read data, especially in bulk.
-
Currently the following sources are supported:
Google Finance
Morningstar
IEX
Robinhood
Enigma
Quandl
St.Louis FED (FRED)
Kenneth French’s data library
World Bank
OECD
Eurostat
Thrift Savings Plan
Nasdaq Trader symbol definitions
Stooq
MOEX