def para_hide(self): global l1, l2, df if self.btn12.text() == '隐藏指标参数': df.columns = l1 self.btn12.setText('显示指标参数') self.model = pandasModel(df) self.view.setModel(self.model) self.view.updateEditorData() else: df.columns = l2 self.btn12.setText('隐藏指标参数') self.model = pandasModel(df) self.view.setModel(self.model) self.view.updateEditorData()
def get_data(self): global l3 code_list = df['基金代码'].tolist() code_str = ','.join(code_list) if self.btn12.text() == '显示指标参数': self.para_hide() for i in range(4, len(l3)): if l3[i][0] == '单位净值': d = w.wsd(code_str, "nav", l3[i][1], l3[i][1]) df[l2[i]] = d.Data[0] elif l3[i][0] == '收益率': d1 = w.wsd(code_str, "nav", l3[i][1], l3[i][1]).Data[0] d2 = w.wsd(code_str, "nav", l3[i][2], l3[i][2]).Data[0] d = [(i - j) / j for i, j in zip(d2, d1)] df[l2[i]] = d elif l3[i][0] == '最大回撤': d = w.wsd(code_str, "risk_maxdownside", l3[i][1], l3[i][2]) print(d.Data) df[l2[i]] = [i[0] for i in d.Data] elif l3[i][0] == '换手率': d = w.wsd( code_str, 'style_rpt_turn', '2020-07-27', '2020-07-27', 'year={0};Intervaltype={1}'.format(l3[i][1], l3[i][2])) print(d.Data) df[l2[i]] = d.Data[0] self.model = pandasModel(df) self.view.setModel(self.model) self.view.updateEditorData()
def add_row_show(self): global df, dl_add_row df0 = dl_add_row.df0 print(df) df = pd.concat([df, df0]) df[''] = range(0, len(df)) df.reset_index(drop=True, inplace=True) print(df) self.model = pandasModel(df) self.view.setModel(self.model) self.view.updateEditorData() self.plot_tree2()
def del_row(self): global df index = self.view.selectionModel().selectedIndexes() list1 = list(set([i.row() for i in index])) list1.sort(key=int, reverse=True) print('list1: ', list1) for i in list1: df = df.drop(index=i) df[''] = range(len(df)) df.reset_index(drop=True, inplace=True) print(df) self.model = pandasModel(df) self.view.setModel(self.model) self.view.updateEditorData()
def fund_show(self): global df, dl_f df0 = dl_f.df0 df = pd.DataFrame(data=None, columns=df.columns.tolist()) print(df) df = pd.concat([df, df0]) df.drop_duplicates(subset=['基金代码'], keep='last', inplace=True) df[''] = range(0, len(df)) df.reset_index(drop=True, inplace=True) print(df) self.model = pandasModel(df) self.view.setModel(self.model) self.view.updateEditorData() self.plot_tree2()
def del_col(self): global df, l1, l2, l3 index = self.view.selectionModel().selectedIndexes() list1 = list(set([i.column() for i in index])) list1.sort(key=int, reverse=True) print('list1: ', list1) for i in list1: if i not in [0, 1, 2, 3]: df = df.drop(columns=list(df)[i], axis=1) del l1[i], l2[i], l3[i] df.reset_index(drop=True, inplace=True) print(df) self.model = pandasModel(df) self.view.setModel(self.model) self.view.updateEditorData() print(l1, l2, l3)
def set_col(self): global l1, l2, df flag = False if self.btn12.text() == '显示指标参数': df.columns = l2[:df.shape[1]] flag = True for i in l2: if i not in df.columns.tolist(): df[i] = None for i in df.columns.tolist(): if i not in l2: df = df.drop(columns=i, axis=1) #print('l2:', l2, '\ncolumn:', df.columns.tolist(), '\nl1:', l1) if flag: df.columns = l1 print(df) self.model = pandasModel(df) self.view.setModel(self.model) self.view.updateEditorData()
def _rank(self): #获取所选列数 global df, l1, l2, l3, dl_rank index = self.view.selectionModel().selectedIndexes() list1 = list(set([i.column() for i in index])) list1.sort(key=int, reverse=False) for i in list1: if i >= 4: col_index = i break #排序 p = dl_rank.proportion ascend_flag = (p < 0) if dl_rank.ckeck_state: df = df.sort_values(by=['类别', l2[col_index]], axis=0, ascending=ascend_flag) else: df = df.sort_values(by=l2[col_index], axis=0, ascending=ascend_flag) #选取 if dl_rank.ckeck_state: l = list(set(df['类别'].tolist())) df0 = df[df['类别'] == l[0]] df0 = df0.iloc[:math.ceil((len(df0) * abs(p) / 100))] for i in range(1, len(l)): df_temp = df[df['类别'] == l[i]] df_temp = df_temp.iloc[:math.ceil((len(df_temp) * abs(p) / 100))] df0 = pd.concat([df0, df_temp]) df = df0 else: df = df.iloc[:int(len(df) * abs(p) / 100)] df[''] = list(range(len(df))) df.reset_index(drop=True, inplace=True) self.model = pandasModel(df) self.view.setModel(self.model) self.view.updateEditorData()
def tableView(self): self.model = pandasModel(df) self.view = QTableView() self.view.setModel(self.model) self.view.setSelectionMode(QTableView.ExtendedSelection) self.hlt_main.addWidget(self.view)