2018-12-30 (Python读取股票数据-Tushare国内)

1. Find pip.exe in folder:

C:\WPy-3670\python-3.6.7.amd64\Scripts

2. Download tushare wheel files

https://pypi.org/

search "tushare"

download file to directory C:\WPy-3670\python-3.6.7.amd64\Scripts

3. Install tushare

C:\WPy-3670\python-3.6.7.amd64\Scripts>pip install tushare

4. Use tushare to load data

import tushare as ts

import matplotlib.pyplot as plt

import datetime

ticker = '600661'

finance=ts.get_hist_data(ticker, '2015-12-03', '2017-12-30')

5. 绘图

已经得到了一个 DataFrame 对象finance,下面绘制出以时间为横坐标,开盘价为纵坐标的折线图

opens = [q for q in finace["open"]]

#dates = [datetime.datetime.strptime(q.encode('utf-8') ,"%Y-%m-%d") for q in finace.index]

dates = [datetime.datetime.strptime(q,"%Y-%m-%d") for q in finace.index]

fig = plt.figure()

ax = fig.add_subplot(111)

ax.plot_date(dates, opens, '-')

fig.autofmt_xdate()

plt.show()

---------------------

作者:Awin_Ge

来源:CSDN

原文:https://blog.csdn.net/ge341204/article/details/81046101

6. 列出股票数据

import tushare as ts

d = ts.get_tick_data('601318',date='2017-06-26')

print (d)

e = ts.get_hist_data('601318',start='2017-06-23',end='2017-06-26')

print (e)

你可能感兴趣的:(2018-12-30 (Python读取股票数据-Tushare国内))