本文主要是介绍日周月,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
# -*- coding:utf-8 -*- import pandas as pd import pymysql from sqlalchemy import create_engine ## 加上字符集参数,防止中文乱码 dbconn = pymysql.connect(host="127.0.0.1",database="fight",user="root",password="111111",port=3306,charset='utf8') conn = create_engine('mysql+mysqldb://root:111111@localhost:3306/fight?charset=utf8') # # sqlcmd = "select * from shape_mode_k7f3" # # # data = pd.read_sql(sqlcmd, dbconn) # data.set_index('mkdate') # # print data[data.mkdate>'2018-02-09'][data.secode<'SZ000975']['mkdate'].drop_duplicates() # # defdff = data['2018-02-09':'2018-02-030'] # # print defdff import tushare as tsdf1 = ts.get_k_data('600167', ktype='D', start='2017-03-06', end='2017-05-03')#Index([u'date', u'open', u'close', u'high', u'low', u'volume', u'code'], dtype='object') df = ts.get_stock_basics()#Index([u'name', u'industry', u'area', u'pe', u'outstanding', u'totals', # u'totalAssets', u'liquidAssets', u'fixedAssets', u'reserved', # u'reservedPerShare', u'esp', u'bvps', u'pb', u'timeToMarket', u'undp', # u'perundp', u'rev', u'profit', u'gpr', u'npr', u'holders'], # dtype='object') codelist = ['000001','000002','300104'] for code in codelist:print codedf = ts.get_hist_data(code=code, start=None, end=None, ktype='D', retry_count=3, pause=0.001)df['code']=codeif not df.empty:try:pd.io.sql.to_sql(df,"kkk",con=conn,if_exists='append')#只能说使用createegien的方式 except Exception as e:print 'Error',eelse:pass
这篇关于日周月的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!