类似于excel中的vlookup功能

def xx_pandas(duiying_path, input_path=None, output_path=None):
    data = pd.read_excel(duiying_path, sheetname='name')
    en_ch = {}  # 英文字段到中文字段的映射
    col1 = data['数据库名称'.decode('utf8')]
    col2 = data['字段名称'.decode('utf8')]
    for i in range(len(col1)):
        if str(col1[i]) == 'nan':
            continue
        en_ch[col1[i]] = col2[i].strip()
    old_data = pd.read_excel(input_path, sheetname='Sheet1')
    ch_names = {}
    index = []
    for l in old_data.index:
        ch_name = ''
        if l in en_ch:
            ch_name = en_ch[l]
        ch_names[l] = ch_name
        index.append(l)
    s = Series(ch_names, name='数据库字段')
    old_data.insert(0, '数据库字段', s)
    print old_data.head(100)
    old_data.to_excel(output_path)

 

posted @ 2015-02-06 13:57  ilxx1988  阅读(705)  评论(1编辑  收藏  举报