PHP调用tushare,在Docker中基于Jupyter Notebook中使用Tushare

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

安装Docker上的Jupyter Notebook

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

注意:我们将端口改为8800,按照提示运行时注意修改端口。

安装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内置的函数绘图:

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,参考:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值