一、所需模块pandas_datareader的安装
(python2) [root@DL ~]# pip install pandas_datareader #用conda install panda_datareader提示找不到软件包,故改为pip install。
...
Installing collected packages: lxml, idna, chardet, urllib3, requests, pandas-datareader
Successfully installed chardet-3.0.4 idna-2.9 lxml-4.5.1 pandas-datareader-0.8.1 requests-2.24.0 urllib3-1.25.9
二、示例
import numpy as np
import pandas as pd
import pandas_datareader.data as web
import datetime
df_csvsave = web.DataReader("000858.SZ", "yahoo",datetime.datetime(2020,1,1),datetime.date.today())
#说明:"000858.SZ",若是上市股票,后缀为SS,深市股票(包括创业版、中小板),后缀为SZ。“yahoo”,表示从yahoo网获取数据来源。
print df_csvsave
结果:
High Low Open Close Volume
Date
2020-01-02 133.500000 129.589996 132.000000 132.080002 30667439.0
2020-01-03 132.070007 129.610001 131.600006 130.550003 20469248.0
2020-01-06 130.250000 128.520004 130.000000 129.199997 25936979.0