获取excel中关键字所在行 python


def saveAsNewExcelFile(input_file_path_plan):
    # get cared macro info from testplan and save as 'MacroInfo.xlsx'
    getInfo = pd.read_excel(input_file_path_plan, sheet_name="frequency_plan", dtype=str, keep_default_na=False)
    for i in getInfo.index:
        for j in range(len(getInfo.loc[i].values)):
            if (getInfo.loc[i].values[j] == 'Macro Info'):
                start_col = i + 1
                break #add 2.3
                # print(getInfo.loc[i].values[j])
    x = pd.DataFrame(getInfo.iloc[start_col:, ])

    # 判断是否存在output文件夹
    if (os.path.exists(OutputPath)):
        shutil.rmtree(OutputPath)
        print('output dir has been rm -rf and new makedirs')
    os.makedirs(OutputPath)

    # 写入文件保存在output 文件夹下
    filepath = os.path.join(OutputPath, 'MacroInfo.xlsx')
    x.to_excel(filepath, header=0, index=False, encoding='utf-8', sheet_name='frequency_plan')

上一篇:缺陷密度


下一篇:pandas 数据索引与选取