python : jdbc 连接 h2数据库,pandas 绘基金净值图

python 2.7 使用jdbc连接数据库,要用到 JayDeBeApi 包,JayDeBeApi 包依赖 JPype1 包.

pip install JayDeBeApi

jdbc 连接 h2数据库,绘基金净值图,h2_jdbc_mpl.py

# -*- coding: cp936 -*-
import os, sys
import jaydebeapi

if len(sys.argv)==2:
    fund1 = sys.argv[1]
else:
    print ' usage: h2_jdbc_mpl.py fundcode'
    sys.exit(4)

if not ( fund1.isdigit() and len(fund1)==6):
    print ' fundcode is 6 位数字.'
    sys.exit(4)

url ='jdbc:h2:tcp://localhost/~/test'
user ='sa'
password =''
dirver ='org.h2.Driver'
jar ='/H2/bin/h2-1.3.jar'
##jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
conn =jaydebeapi.connect(dirver,url,[user,password],jar)
curs = conn.cursor()

select ="select MC from JJMC where DM=" + fund1
curs.execute(select)
fundname = curs.fetchall()
#print(fundname)

import pandas as pd
import pandas.io.sql as psql

query ="select RQ,JZ from JJJZ where DM=%s order by 1" % (fund1)
# dataFrame
df = psql.read_sql_query(query,conn)

curs.close()
conn.close()

import matplotlib.pyplot as plt
# 加这个两句 可以显示中文
plt.rcParams['font.sans-serif'] = [u'SimHei']
plt.rcParams['axes.unicode_minus'] = False

fname = fund1 + fundname[0][0] # 基金代码 + 基金名称 
# 基金净值绘图
df['JZ'].plot(figsize=(12,6), grid=True, title=fname)
# 画30日移动平均线  
pd.rolling_mean(df['JZ'], 30).plot(grid=True)
plt.show()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值