# 导入tushareimport tushare as ts# 初始化pro接口pro = ts.pro_api('')data = pro.query('stock_basic', exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date')## print(data)# # print(data['symbol'] + ':' + data['ts_code'] + ':' + data['name'])# print('A股所有股票数:' + str(len(data)))# print(type(data))# print(type(data['ts_code']))# print(data['ts_code'][0])# print(data['ts_code'][1])# print(data['name'][0])# print(data['name'][1])# print('*********************')start_date = '0101'end_date = '0101'for i in range(5):print('++++++++++++++++++++++++++++++++++++++')print(data['name'][i] + ':' + data['ts_code'][i])# 拉取数据df = pro.daily(**{"ts_code": data['ts_code'][i],"trade_date": "","start_date": start_date,"end_date": end_date,"offset": "","limit": ""}, fields=["ts_code","trade_date","open","high","low","close","pre_close","change","pct_chg","vol","amount"])# 拉取数据nowPriec = pro.daily(**{"ts_code": data['ts_code'][i],"trade_date": "","start_date": 0106,"end_date": 0106,"offset": "","limit": ""}, fields=["close"])# print(df)# print(type(df))print('max price.mix price:')# print(max(df['close']))# print(min(df['close']))print(max(df['close']))print(min(df['close']))# print('percent: {:.2%}'.format(42 / 50))# (max(df['close'])-min(df['close']))/max(df['close'])print('涨跌幅 percent: {:.2%}'.format((max(df['close'])-min(df['close']))/min(df['close'])))print('最高点最低点的涨跌幅')# print(nowPriec)print(float(nowPriec['close']))# print(type(nowPriec))print('涨幅: {:.2%}'.format((max(df['close']) - float(nowPriec['close'])) / float(nowPriec['close'])))print('跌幅: {:.2%}'.format((min(df['close']) - float(nowPriec['close'])) / float(nowPriec['close'])))
700字范文,内容丰富有趣,生活中的好帮手!