import pandas as pd df_bom = pd.read_excel('bom23.xlsx', engine='openpyxl') df_plan = pd.read_excel('plan.xlsx', engine='openpyxl') def get_bom_by_prd_id(prd_id): df_sub = df_bom.loc[df_bom['prd_id'] == prd_id] return df_sub[['mtr_id', 'qty']] def get_plan_by_pp_id(pp_id): df_sub = df_plan.loc[df_plan['pp_id'] == int(pp_id)] return df_sub[['prd_id', 'size', 'rate']] if __name__ == '__main__': print(get_bom_by_prd_id('ADTB331M0611')) print(get_plan_by_pp_id('0')) # 0, 6, 8, 10