import pandas as pd
import yaml

df = pd.read_excel(r'C:\Users\wzl\Desktop\中广核104测点\0416部署需要\故障报警\故障代码表.xlsx')

result_json = dict()

for index, row in df.iterrows():
    mc_id = row['主控ID'].strip()
    code = row['状态编码']
    en_name = row['SC中文描述'].strip()
    level = str(row['告警等级']).strip()
    if mc_id in result_json.keys():
        result_json[mc_id][code] = {'en_name': en_name, 'level': level}
    else:
        result_json[mc_id] = {code: {'en_name': en_name, 'level': level}}

yaml_str = yaml.dump(result_json, allow_unicode=True, sort_keys=False)
with open('warn_fault.yaml', 'w', encoding='utf8') as f:
    f.write(yaml_str)
