在Docker中基于Jupyter Notebook中使用Tushare

Tushare( http://tushare.org )是一个多种数据集成API,能够抓取股市、电影票房等多种公开来源的数据,使用pandas( http://pandas.pydata.org/ )的DadaFrame做为内存数据结构,能够使用Python的多种接口访问,以及经过matplot绘制图表。python

安装Docker上的Jupyter Notebook

docker run --name notebook --restart always -it -p 8800:8888 jupyter/all-spark-notebook

注意:咱们将端口改成8800,按照提示运行时注意修改端口。docker

安装Tushare

在浏览器打开jupyter notebook服务地址,建立一个终端窗口。浏览器

安装软件:数据结构

pip install lxml
pip install tushare

运行Tushare

打开一个python3的notebook窗口,输入下面的代码,按shift+enter便可运行。函数

import matplotlib
import tushare as ts
import pandas as pd
import matplotlib.pyplot as plt

df=ts.get_hist_data('300036',start='2016-01-01',end='2017-01-01')

绘制图形

首先使用pandas内置的函数绘图:spa

with pd.plot_params.use('x_compat', True):
    df.high.plot(color='r',figsize=(10,4),grid='on')
    df.low.plot(color='b',figsize=(10,4),grid='on')
    fig.savefig('/Users/david/pythongraph/graph000001.png')

若是使用Matplot绘图,须要首先运行 %matplot inline,参考:.net

相关文章
相关标签/搜索