27 lines
994 B
Python
Executable File
27 lines
994 B
Python
Executable File
# -*- coding: utf-8 -*-
|
|
import pandas as pd
|
|
|
|
db = pd.read_csv('db_bom2.csv', dtype=str)
|
|
db['code'] = db['ChildMaterialId'].astype(str).str.strip()
|
|
db['parent'] = db['ParentMaterialId'].astype(str).str.strip()
|
|
|
|
out = []
|
|
# 数据库中 9000013420-A01 的4个子件
|
|
kids = db[db['parent'] == '9000013420-A01']
|
|
out.append(f"数据库 9000013420-A01 子件数: {len(kids)}")
|
|
for _, r in kids.iterrows():
|
|
out.append(f" {r['code']} {r['MaterialName']} Level={r['Level']}")
|
|
|
|
# 这4个子件在数据库其他地方是否也出现(比如 1.11.2 直接子件)
|
|
for c in kids['code']:
|
|
hits = db[(db['code'] == c) & (db['parent'] != '9000013420-A01')]
|
|
if len(hits) > 0:
|
|
for _, h in hits.iterrows():
|
|
out.append(f" {c} 也出现在 父级={h['parent']} (Level={h['Level']})")
|
|
else:
|
|
out.append(f" {c} 仅出现在 9000013420-A01 下")
|
|
|
|
with open('cmp_3420.txt', 'w', encoding='utf-8') as f:
|
|
f.write('\n'.join(out))
|
|
print("done")
|