df = pd.DataFrame(np.random.randint(1, 10, [3,3]), columns = list('ABC'))
通过 dict 制造key
index_htable={}
for _,row in idc.iterrows(): #按行循环
key = str(row[u'股票代码']) + '|' +str(row[u'日期']) #根据不同 的索引重新制作键值
value = str(row[u'指数代码'])
if value == '000300.SH':
value = '沪深300'
else:
value = '其他'
index_htable[key] = value # 对值重新定义索引和名称
def find_index_constitutes(code):
key = str(code[0]) + '|' + str(code[1])
if key in index_htable: # 搜寻键对应的值
print('found key',key,index_htable[key])
return index_htable[key]
else:
return '其他'