小工具

# -*- coding: utf-8 -*-
import pandas as pd

def filterExcel(cokpath, keywords):
    df = pd.read_excel(cokpath)
    data_dict = df.to_dict()
    res_dic = {"名字": [], "登记": [], "坐标": []}
    for k, v in data_dict["名字"].items():
        if v.startswith(keywords):
            res_dic["名字"].append(v)
            res_dic["登记"].append(data_dict["登记"][k])
            res_dic["坐标"].append(data_dict["坐标"][k])

    data_frame = pd.DataFrame(res_dic)
    data_frame.to_excel('{0}-INFO.xls'.format(keywords), sheet_name='cok_lgd')

if __name__ == '__main__':
    COKPATH = input("请输入待处理的Excel文件路径:")
    ALLIANCE_NAME = input("请输入需要筛选的联盟名称:")
    keywords = "({0})".format(ALLIANCE_NAME)
    filterExcel(COKPATH, keywords)

  

05-11 09:31