# -*- coding: utf-8 -*- import pandas as pd kd = pd.read_excel('物料清单正查_1.xlsx', sheet_name='树形单据体') kd = kd[kd['子项物料编码'].notna()].copy() kd['code'] = kd['子项物料编码'].astype(str).str.strip() kd['name'] = kd['物料名称'].astype(str).str.strip() kd['lv'] = kd['BOM层级'].astype(str).str.strip() out = [] # 模糊搜索 LORA / 天线 / 9000013420 for kw in ['LORA', 'LoRa', 'lora', '天线', '9000013420']: sub = kd[kd.apply(lambda r: kw in str(r['code']) or kw in str(r['name']), axis=1)] out.append(f"=== 关键词 [{kw}] 匹配 {len(sub)} 行 ===") for _, r in sub.iterrows(): out.append(f" 层级={r['lv']} 编码={r['code']} 名称={r['name']} 跳层={r['是否跳层']} BOM版本={r['BOM版本']}") with open('kd_lora.txt', 'w', encoding='utf-8') as f: f.write('\n'.join(out)) print("done")