tushare包使用学习

环境依赖

  1. pandas,lxml,bs4是turshare的依赖包(虽然安装的时候不装bs4也行,但是import的时候会报错)
  2. 除此之外,导出excel时提示openpyxl(是1不是L) conda install openpyxl
  3. seaborn是可视化包,也一并装了
  4. ts.get_sz50s()调用时提示没有xlrd包,pip install xlrd,也是与excel有关

导出数据

导出数据(注意路径是右斜杠,不是windows默认的左斜杠)
df.to_excel(‘c:/day/000875.xlsx’)
df.to_hdf(‘c:/day/hdf.h5’,‘000875’)
df.to_json(‘c:/day/000875.json’,orient=‘records’)
df.to_csv(‘c:/day/000875.csv’)

from sqlalchemy import create_engine
import tushare as ts
df = ts.get_tick_data(‘600848’, date=‘2014-12-22’)
engine = create_engine(‘mysql://user:[email protected]/db_name?charset=utf8’)
#存入数据库
df.to_sql(‘tick_data’,engine)
#追加数据到现有表
#df.to_sql(‘tick_data’,engine,if_exists=‘append’)

ptyhon查看函数的工具

#使用inspect模块,简单方便
import inspectinspect.getargspec(f)
#使用f的内置方法#获取默认值,如果参数名没有默认值则不在其中:
print(f.defaults)#使用__code__#总参数个数
print(f.code.co_argcount)#总参数名
print(f.code.co_varnames)

ps:
查看全部代码 inspect.getsource(模块.函数)或者(模块.类.函数)
查看函数参数 inspect.getargspec(…)   查看类的参数,则括号里为(模块.类.init
inspect.getfullargspec()上面那个好像被废弃了
查看函数的位置 inspect.getabsfile(…)

猜你喜欢

转载自blog.csdn.net/qq_29809823/article/details/85159587