编程语言
首页 > 编程语言> > 获取excel中关键字所在行 python

获取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')

标签:loc,getInfo,python,excel,OutputPath,关键字,plan,path
来源: https://blog.csdn.net/weixin_43931151/article/details/113845633