python自动炒股软件下载_pandas-在python中自动从Yahoo Finance下载历史股票价格

用实际演示扩展@Def_Os的答案…

正如@Def_Os已经说过的-使用Pandas Datareader使这项任务真正有趣

In [12]: from pandas_datareader import data

从1980-01-01开始拉取AAPL的所有可用历史数据

#In [13]: aapl = data.DataReader(‘AAPL’, ‘yahoo’, ‘1980-01-01’)

# yahoo api is inconsistent for getting historical data, please use google instead.

In [13]: aapl = data.DataReader(‘AAPL’, ‘google’, ‘1980-01-01’)

前5行

In [14]: aapl.head()

Out[14]:

Open High Low Close Volume Adj Close

Date

1980-12-12 28.750000 28.875000 28.750 28.750 117258400 0.431358

1980-12-15 27.375001 27.375001 27.250 27.250 43971200 0.408852

1980-12-16 25.375000 25.375000 25.250 25.250 26432000 0.378845

1980-12-17 25.875000 25.999999 25.875 25.875 21610400 0.388222

1980-12-18 26.625000 26.750000 26.625 26.625 18362400 0.399475

最后5行

In [15]: aapl.tail()

Out[15]:

Open High Low Close Volume Adj Close

Date

2016-06-07 99.250000 99.870003 98.959999 99.029999 22366400 99.029999

2016-06-08 99.019997 99.559998 98.680000 98.940002 20812700 98.940002

2016-06-09 98.500000 99.989998 98.459999 99.650002 26419600 99.650002

2016-06-10 98.529999 99.349998 98.480003 98.830002 31462100 98.830002

2016-06-13 98.690002 99.120003 97.099998 97.339996 37612900 97.339996

将所有数据另存为CSV文件

In [16]: aapl.to_csv(‘d:/temp/aapl_data.csv’)

d:/temp/aapl_data.csv-前5行

Date,Open,High,Low,Close,Volume,Adj Close

1980-12-12,28.75,28.875,28.75,28.75,117258400,0.431358

1980-12-15,27.375001,27.375001,27.25,27.25,43971200,0.408852

1980-12-16,25.375,25.375,25.25,25.25,26432000,0.378845

1980-12-17,25.875,25.999999,25.875,25.875,21610400,0.38822199999999996

1980-12-18,26.625,26.75,26.625,26.625,18362400,0.399475

文章知识点与官方知识档案匹配,可进一步学习相关知识Python入门技能树结构化数据分析工具PandasPandas概览209056 人正在系统学习中 相关资源:ExWinner成套 价软件

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年11月9日
下一篇 2020年11月9日

相关推荐