前言:
续上一篇文章的代码
index_data.py
from __future__ import (absolute_import, division, print_function, unicode_literals)
import pandas as pd
import tushare as ts
import mplfinance as mpf
import tkinter as tk
import tkinter.tix as tix
from tkinter.constants import *
import matplotlib.pyplot as plt
import matplotlib.dates as mdates # 处理日期
import matplotlib as mpl # 用于设置曲线参数
import datetime
import tk_window
mpl.use('TkAgg')
pro = ts.pro_api('数据用的是tushare,没权限自己去注册个吧')
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
# 解决mplfinance绘制输出中文乱码
s = mpf.make_mpf_style(base_mpf_style='yahoo', rc={
'font.family': 'SimHei'})
# pd.set_option()就是pycharm输出控制显示的设置
pd.set_option('expand_frame_repr', False) # True就是可以换行显示。设置成False的时候不允许换行
pd.set_option('display.max_columns', None) # 显示所有列
# pd.set_option('display.max_rows', None) # 显示所有行
pd.set_option('colheader_justify', 'centre') # 显示居中
def stockindex_function(): # 全景功能代码
# 必须添加以下控件销毁代码,不然点击一次按钮框架长生一次,显示的画面会多一次,你可以将下面的代码删除测试看下
for widget_graphic_main_frame in tk_window.centre_frame.winfo_children():
widget_graphic_main_frame.destroy()
stockindex_window = tk.PanedWindow(tk_window.centre_frame, orient='vertical', opaqueresize=False)
stockindex_window.pack(fill=BOTH, expand=1)
stockindex_top_frame = tk.Frame(stockindex_window, bg='#353535', bd=5, borderwidth=4)
stockindex_top_frame.pack(fill=BOTH, expand=1)
# 创建顶部左边框架
stockindex_top_left_frame = tk.Frame(stockindex_top_frame, bg='#353535')
stockindex_top_left_frame.pack(side=tk.LEFT, padx=tk_window.screenHeight / 4.2)
# 在顶部左边框架创建标签‘日期’
date_label = tk.Label(stockindex_top_left_frame, text='日期', bd=1, bg='#353535', fg='red')
date_label.pack(side=tk.LEFT, padx=4)
# 在顶部左边框架创建开始日期代码输入框
input_date_var = tk.StringVar()
inputdate_widget = tk.Entry(stockindex_top_left_frame, textvariable=input_date_var, borderwidth=1,
justify=tk.CENTER)
inputdate_widget.pack(side=tk.LEFT, padx=4)
# 创建顶部右边边框架
stockindex_top_right_frame = tk.Frame(stockindex_top_frame, bg='#353535')
stockindex_top_right_frame.pack(fill=tk.BOTH)
# 开始结束日期标签输入框代码
start_date_label = tk.Label(stockindex_top_right_frame, text='开始日期', bd=1, bg='#353535', fg='red')
start_date_label.pack(side=tk.LEFT, padx=4)
start_input_date_var = tk.StringVar()
start_inputdate_widget = tk.Entry(stockindex_top_right_frame, textvariable=start_input_date_var, borderwidth=1,
justify=tk.CENTER)
start_inputdate_widget.pack(side=tk.LEFT, padx=4)
end_date_label = tk.Label(stockindex_top_right_frame, text='结束日期', bd=1, bg='#353535', fg='red')
end_date_label.pack(side=tk.LEFT, padx=4)
end_input_date_var = tk.StringVar()
end_inputdate_widget = tk.Entry(stockindex_top_right_frame, textvariable=end_input_date_var, borderwidth=1,
justify=tk.CENTER)
end_inputdate_widget.pack(side=tk.LEFT, padx=4)
stockindex_window.add(stockindex_top_frame)
# 创建底下显示框架,再次添加一个子窗口,并在窗口下创建显示frame框架,作用负责刷新,生成的数据不重叠
stockindex_bottom_window = tk.PanedWindow(orient='vertical', opaqueresize=False)
stockindex_window.add(stockindex_bottom_window)
stockindex_bottom_frame = tk.Frame(stockindex_bottom_window, relief=tk.SUNKEN, bg='#353535', bd=5, borderwidth=4)
stockindex_bottom_frame.pack()
stockindex_bottom_window.add(stockindex_bottom_frame)
def data_show():
for widget_stockindex_bottom_frame in stockindex_bottom_frame.winfo_children():
widget_stockindex_bottom_frame.destroy()
# 在右边窗口的graphic_main_frame框架下再创建窗口
# opaqueresize该选项的值为 False,窗格的尺寸在用户释放鼠标的时候才更新到新的位置
stockindex_information_window = tk.PanedWindow(stockindex_bottom_frame, opaqueresize=False)
stockindex_information_window.pack(fill=BOTH, expand=1)
# 在company_information_window窗口下设置指数信息显示功能
stockindex_text = tk.Text(stockindex_information_window, bg='white', undo=True, wrap=tix.CHAR)
stockindex_information_window.add(stockindex_text, width=tk_window.screenWidth / 6.4)
# 首先获取今天时间
# now_time = datetime.datetime.now()
# 转化成tushare的时间格式
strf_time = input_date_var.get()
# 获取上交所上一个交易日日期,PS:tushare指数的数据信息好像当天只能获取上一个交易日的数据
pre_trade_date = pro.trade_cal(exchange='SSE', is_open='1', start_date=strf_time, fields='pretrade_date')
# print(pre_trade_date)
pre_trade_d = pre_trade_date.at[0, 'pretrade_date']
# print(pre_trade_d)
shsz_index_dailybasic = pro.index_dailybasic(trade_date=pre_trade_d, fields='ts_code,trade_date, '
'total_mv,float_mv, total_share, '
'float_share, free_share, '
'turnover_rate, turnover_rate_f, '
'pe, pb')
sh_index_daily = pro.index_daily(ts_code='000001.SH', trade_date=pre_trade_d)
sz_index_daily = pro.index_daily(ts_code='399001.SZ', trade_date=pre_trade_d)
cy_index_daily = pro.index_daily(ts_code='399006.SZ', trade_date=pre_trade_d)
zx_index_daily = pro.index_daily(ts_code='399005.SZ', trade_date=pre_trade_d)
# print(sh_index_daily)
# 数据处理,将ts_code作为索引,方便准确调用数据,保留两位小数
shsz_index_dailybasic.set_index('ts_code', inplace=True)
# 数据获取
sh_total_mv = round(shsz_index_dailybasic.at['000001.SH', 'total_mv'] / 100000000, 2) # 元转换成亿单位
sh_float_mv = round(shsz_index_dailybasic.at['000001.SH', 'float_mv'] / 100000000, 2)
sh_total_share = round(shsz_index_dailybasic.at['000001.SH', 'total_share'] / 10000000000, 2) # 股转化成亿手
sh_float_share = round(shsz_index_dailybasic.at['000001.SH', 'float_share'] / 10000000000, 2)
sh_free_share = round(shsz_index_dailybasic.at['000001.SH', 'free_share'] // 10000000000, 2)
sh_turnover_rate = shsz_index_dailybasic.at['000001.SH', 'turnover_rate']
sh_pe = shsz_index_dailybasic.at['000001.SH', 'pe']
sh_pb = shsz_index_dailybasic.at['000001.SH', 'pb']
sh_close = sh_index_daily.at[0, 'close']
sh_pre_close = sh_index_daily.at[0, 'pre_close']
sh_pct_chg = sh_index_daily.at[0, 'pct_chg']
sh_vol = round(sh_index_daily.at[0, 'vol'] / 100000000, 2) # 手转化成亿手
sh_amount = round(sh_index_daily.at[0, 'amount'] / 100000, 2) # 千元转换成亿元
# 数据调用
# 在文本框第一行添加股票代码,文字红色,居中显示
stockindex_text.insert(tk.INSERT, '上证指数')
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '总市值(亿):')
stockindex_text.insert(tk.INSERT, sh_total_mv)
stockindex_text.tag_add('tag1', '1.0', '1.9') # 设置选定的内容
stockindex_text.tag_config('tag1', foreground='red', justify=CENTER)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '流通市值(亿):')
stockindex_text.insert(tk.INSERT, sh_float_mv)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '总股本(亿手):')
stockindex_text.insert(tk.INSERT, sh_total_share)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '流通股本(亿手):')
stockindex_text.insert(tk.INSERT, sh_float_share)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '自由流通股本(亿手):')
stockindex_text.insert(tk.INSERT, sh_free_share)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '换手率:')
stockindex_text.insert(tk.INSERT, sh_turnover_rate)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '市盈率:')
stockindex_text.insert(tk.INSERT, sh_pe)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '市净率:')
stockindex_text.insert(tk.INSERT, sh_pb)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '收盘点位:')
stockindex_text.insert(tk.INSERT, sh_close)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '昨日收盘点:')
stockindex_text.insert(tk.INSERT, sh_pre_close)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '涨跌幅(%):')
stockindex_text.insert(tk.INSERT, sh_pct_chg)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '成交量(亿手):')
stockindex_text.insert(tk.INSERT, sh_vol)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '成交额(亿):')
stockindex_text.insert(tk.INSERT, sh_amount)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.tag_add('content1', '2.0', 'end') # 设置选定的内容
stockindex_text.tag_config('content1', foreground='blue')
sz_total_mv = round(shsz_index_dailybasic.at['399001.SZ', 'total_mv'] / 100000000, 2) # 转换成亿单位
sz_float_mv = round(shsz_index_dailybasic.at['399001.SZ', 'float_mv'] / 100000000, 2)
sz_total_share = round(shsz_index_dailybasic.at['399001.SZ', 'total_share'] / 10000000000, 2) # 转化成亿手
sz_float_share = round(shsz_index_dailybasic.at['399001.SZ', 'float_share'] / 10000000000, 2)
sz_free_share = round(shsz_index_dailybasic.at['399001.SZ', 'free_share'] // 10000000000, 2)
sz_turnover_rate = shsz_index_dailybasic.at['399001.SZ', 'turnover_rate']
sz_pe = shsz_index_dailybasic.at['399001.SZ', 'pe']
sz_pb = shsz_index_dailybasic.at['399001.SZ', 'pb']
sz_close = sz_index_daily.at[0, 'close']
sz_pre_close = sz_index_daily.at[0, 'pre_close']
sz_pct_chg = sz_index_daily.at[0, 'pct_chg']
sz_vol = round(sz_index_daily.at[0, 'vol'] / 100000000, 2) # 手转化成亿手
sz_amount = round(sz_index_daily.at[0, 'amount'] / 100000, 2) # 千元转换成亿元
stockindex_text.insert(tk.INSERT, '深证指数')
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '总市值(亿):')
stockindex_text.insert(tk.INSERT, sz_total_mv)
stockindex_text.tag_add('tag2', '15.0', '15.9') # 设置选定的内容,
stockindex_text.tag_config('tag2', foreground='red', justify=CENTER)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '流通市值(亿):')
stockindex_text.insert(tk.INSERT, sz_float_mv)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '总股本(亿手):')
stockindex_text.insert(tk.INSERT, sz_total_share)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '流通股本(亿手):')
stockindex_text.insert(tk.INSERT, sz_float_share)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '自由流通股本(亿手):')
stockindex_text.insert(tk.INSERT, sz_free_share)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '换手率:')
stockindex_text.insert(tk.INSERT, sz_turnover_rate)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '市盈率:')
stockindex_text.insert(tk.INSERT, sz_pe)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '市净率:')
stockindex_text.insert(tk.INSERT, sz_pb)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '收盘点位:')
stockindex_text.insert(tk.INSERT, sz_close)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '昨日收盘点:')
stockindex_text.insert(tk.INSERT, sz_pre_close)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '涨跌幅(%):')
stockindex_text.insert(tk.INSERT, sz_pct_chg)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '成交量(亿手):')
stockindex_text.insert(tk.INSERT, sz_vol)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '成交额(亿):')
stockindex_text.insert(tk.INSERT, sz_amount)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.tag_add('content2', '16.0', 'end') # 设置选定的内容
stockindex_text.tag_config('content2', foreground='DarkViolet')
cy_total_mv = round(shsz_index_dailybasic.at['399006.SZ', 'total_mv'] / 100000000, 2) # 转换成亿单位
cy_float_mv = round(shsz_index_dailybasic.at['399006.SZ', 'float_mv'] / 100000000, 2)
cy_total_share = round(shsz_index_dailybasic.at['399006.SZ', 'total_share'] / 10000000000, 2) # 转化成亿手
cy_float_share = round(shsz_index_dailybasic.at['399006.SZ', 'float_share'] / 10000000000, 2)
cy_free_share = round(shsz_index_dailybasic.at['399006.SZ', 'free_share'] // 10000000000, 2)
cy_turnover_rate = shsz_index_dailybasic.at['399006.SZ', 'turnover_rate']
cy_pe = shsz_index_dailybasic.at['399006.SZ', 'pe']
cy_pb = shsz_index_dailybasic.at['399006.SZ', 'pb']
cy_close = sh_index_daily.at[0, 'close']
cy_pre_close = cy_index_daily.at[0, 'pre_close']
cy_pct_chg = cy_index_daily.at[0, 'pct_chg']
cy_vol = round(cy_index_daily.at[0, 'vol'] / 100000000, 2) # 手转化成亿手
cy_amount = round(cy_index_daily.at[0, 'amount'] / 100000, 2) # 千元转换成亿元
stockindex_text.insert(tk.INSERT, '创业板指数')
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '总市值(亿):')
stockindex_text.insert(tk.INSERT, cy_total_mv)
stockindex_text.tag_add('tag3', '29.0', '29.9') # 设置选定的内容,
stockindex_text.tag_config('tag3', foreground='red', justify=CENTER)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '流通市值(亿):')
stockindex_text.insert(tk.INSERT, cy_float_mv)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '总股本(亿手):')
stockindex_text.insert(tk.INSERT, cy_total_share)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '流通股本(亿手):')
stockindex_text.insert(tk.INSERT, cy_float_share)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '自由流通股本(亿手):')
stockindex_text.insert(tk.INSERT, cy_free_share)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '换手率:')
stockindex_text.insert(tk.INSERT, cy_turnover_rate)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '市盈率:')
stockindex_text.insert(tk.INSERT, cy_pe)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '市净率:')
stockindex_text.insert(tk.INSERT, cy_pb)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '收盘点位:')
stockindex_text.insert(tk.INSERT, cy_close)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '昨日收盘点:')
stockindex_text.insert(tk.INSERT, cy_pre_close)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '涨跌幅(%):')
stockindex_text.insert(tk.INSERT, cy_pct_chg)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '成交量(亿手):')
stockindex_text.insert(tk.INSERT, cy_vol)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '成交额(亿):')
stockindex_text.insert(tk.INSERT, cy_amount)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.tag_add('content3', '30.0', 'end') # 设置选定的内容
stockindex_text.tag_config('content3', foreground='DarkCyan')
zx_total_mv = round(shsz_index_dailybasic.at['399005.SZ', 'total_mv'] / 100000000, 2) # 转换成亿单位
zx_float_mv = round(shsz_index_dailybasic.at['399005.SZ', 'float_mv'] / 100000000, 2)
zx_total_share = round(shsz_index_dailybasic.at['399005.SZ', 'total_share'] / 10000000000, 2) # 转化成亿手
zx_float_share = round(shsz_index_dailybasic.at['399005.SZ', 'float_share'] / 10000000000, 2)
zx_free_share = round(shsz_index_dailybasic.at['399005.SZ', 'free_share'] // 10000000000, 2)
zx_turnover_rate = shsz_index_dailybasic.at['399005.SZ', 'turnover_rate']
zx_pe = shsz_index_dailybasic.at['399005.SZ', 'pe']
zx_pb = shsz_index_dailybasic.at['399005.SZ', 'pb']
zx_close = zx_index_daily.at[0, 'close']
zx_pre_close = zx_index_daily.at[0, 'pre_close']
zx_pct_chg = zx_index_daily.at[0, 'pct_chg']
zx_vol = round(zx_index_daily.at[0, 'vol'] / 100000000, 2) # 手转化成亿手
zx_amount = round(zx_index_daily.at[0, 'amount'] / 100000, 2) # 千元转换成亿元
stockindex_text.insert(tk.INSERT, '中小板指数')
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '总市值(亿):')
stockindex_text.insert(tk.INSERT, zx_total_mv)
stockindex_text.tag_add('tag4', '43.0', '43.9') # 设置选定的内容,
stockindex_text.tag_config('tag4', foreground='red', justify=CENTER)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '流通市值(亿):')
stockindex_text.insert(tk.INSERT, zx_float_mv)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '总股本(亿手):')
stockindex_text.insert(tk.INSERT, zx_total_share)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '流通股本(亿手):')
stockindex_text.insert(tk.INSERT, zx_float_share)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '自由流通股本(亿手):')
stockindex_text.insert(tk.INSERT, zx_free_share)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '换手率:')
stockindex_text.insert(tk.INSERT, zx_turnover_rate)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '市盈率:')
stockindex_text.insert(tk.INSERT, zx_pe)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '市净率:')
stockindex_text.insert(tk.INSERT, zx_pb)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '收盘点位:')
stockindex_text.insert(tk.INSERT, zx_close)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '昨日收盘点:')
stockindex_text.insert(tk.INSERT, zx_pre_close)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '涨跌幅(%):')
stockindex_text.insert(tk.INSERT, zx_pct_chg)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '成交量(亿手):')
stockindex_text.insert(tk.INSERT, zx_vol)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '成交额(亿):')
stockindex_text.insert(tk.INSERT, zx_amount)
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.tag_add('content4', '44.0', 'end') # 设置选定的内容
stockindex_text.tag_config('content4', foreground='Sienna')
stockindex_text.insert(tk.INSERT, '\n')
stockindex_text.insert(tk.INSERT, '数据交易日期:')
stockindex_text.insert(tk.INSERT, pre_trade_d)
stockindex_text.tag_add('content5', '58.0', 'end') # 设置选定的内容
stockindex_text.tag_config('content5', foreground='Crimson')
stockindex_information_window1 = tk.PanedWindow(orient='horizontal', opaqueresize=False)
stockindex_information_window.add(stockindex_information_window1)
stockindex_text1 = tk.Text(stockindex_information_window1, bg='white', undo=True, wrap=tix.CHAR)
stockindex_information_window1.add(stockindex_text1, width=tk_window.screenWidth / 6.4)
# 获取上交所上一个交易日日期,PS:tushare指数的数据信息好像当天只能获取上一个交易日的数据
pre_trade_date = pro.trade_cal(exchange='SSE', is_open='1', start_date=pre_trade_d, fields='pretrade_date')
pre_trade_d1 = pre_trade_date.at[0, 'pretrade_date']
shsz_index_dailybasic = pro.index_dailybasic(trade_date=pre_trade_d1, fields='ts_code,trade_date, '
'total_mv,float_mv, total_share, '
'float_share, free_share, '
'turnover_rate, turnover_rate_f, '
'pe, pb')
sh_index_daily = pro.index_daily(ts_code='000001.SH', trade_date=pre_trade_d1)
sz_index_daily = pro.index_daily(ts_code='399001.SZ', trade_date=pre_trade_d1)
cy_index_daily = pro.index_daily(ts_code='399006.SZ', trade_date=pre_trade_d1)
zx_index_daily = pro.index_daily(ts_code='399005.SZ', trade_date=pre_trade_d1)
# print(sh_index_daily)
# 数据处理,将ts_code作为索引,方便准确调用数据,保留两位小数
shsz_index_dailybasic.set_index('ts_code', inplace=True)
# 数据获取
sh_total_mv = round(shsz_index_dailybasic.at['000001.SH', 'total_mv'] / 100000000, 2) # 元转换成亿单位
sh_float_mv = round(shsz_index_dailybasic.at['000001.SH', 'float_mv'] / 100000000, 2)
sh_total_share = round(shsz_index_dailybasic.at['000001.SH', 'total_share'] / 10000000000, 2) # 股转化成亿手
sh_float_share = round(shsz_index_dailybasic.at['000001.SH', 'float_share'] / 10000000000, 2)
sh_free_share = round(shsz_index_dailybasic.at['000001.SH', 'free_share'] // 10000000000, 2)
sh_turnover_rate = shsz_index_dailybasic.at['000001.SH', 'turnover_rate']
sh_pe = shsz_index_dailybasic.at['000001.SH', 'pe']
sh_pb = shsz_index_dailybasic.at['000001.SH', 'pb']
sh_close = sh_index_daily.at[0, 'close']
sh_pre_close = sh_index_daily.at[0, 'pre_close']
sh_pct_chg = sh_index_daily.at[0,