流通盘提取函数


def add_circulate(mypath,need_list=['sh600000']):
      '追加个股流通盘数据'
      circulate_list = []
      if len(need_list) == 0:
            return circulate_list
      
      print('正在写流通盘,请稍候……')
      n = 0
      wb_base = load_workbook(mypath + 'base\\' + 'base.xlsx')
      ws_base =wb_base.active
      for file_name in need_list:
            if file_name == 'sh000001':
                  continue
            try:
                  wb_target = load_workbook(mypath + 'data\\' + file_name + '.xlsx')
                  ws_target = wb_target.active
                  file_num = file_name[2:8]
                  for i in range(ws_base.max_row):
                        gpdm = str(ws_base.cell(i+2,1).value+1000000)[1:7]
                        if gpdm == file_num:
                              ws_target.cell(2,8).value = '流通股'
                              circulate = 10000 * ws_base.cell(i+2,4).value
                              if circulate == 0:
                                    print(file_name + '找不到流通盘数据')
                                    break
                              ws_target.cell(ws_target.max_row,8).value = circulate
                              circulate_list.append(circulate)
                              break
                  wb_target.save(mypath + 'data\\' + file_name + '.xlsx')
                  wb_target.close()
                  n += 1
            except:
                  print(file_name +
                        '文件数据损坏!!!')
      wb_base.close()
      print('更新流通盘数据::' + str(n) + '\n')
      return circulate_list

猜你喜欢

转载自blog.csdn.net/lee2601/article/details/81084970