import pandas as pd

# ====== 填入你的数据 ======
names = [
"集成电路制造",
"晶圆测试",
"功率半导体器件",
"二极管",
"碳化硅外延晶片",
"氮化镓外延片",
"晶闸管",
"氮化铝外延片",
"磷化铟外延片",
"LED外延片",
"晶体管",
"硅外延片",
"整流桥",
"蚀刻液",
"砷化镓单晶片",
"多晶硅片",
"碳化硅单晶和单晶片",
"磷化铟单晶和单晶片",
"氮化镓晶体和单晶片",
"单晶硅片",
"氮化镓衬底",
"碳化硅衬底",
"磷化铟衬底",
"硅衬底",
"氮化铝衬底",
"深紫外LED衬底",
"氟化硅",
"显影液",
"稀释剂",
"硅原材料",
"聚羧酸减水剂",
"表面活性剂",
"碳化硅",
"高纯金属有机化合物",
"半导体电镀设备",
"晶硅切片机",
"薄膜生长设备",
"硅片倒角机",
"等离子去胶机",
"晶圆清洗机",
"熔炼矿热炉",
"光刻胶及其配套试剂",
"离子注入设备",
"剥离液",
"芯片设计验证",
"金属保护液",
"化学机械抛光设备",
"高纯硼酸（核电）",
"电子级环氧树脂",
"光刻机",
"通用湿电子化学品",
"单晶生长炉",
"晶圆测量设备",
"电子级阻燃材料及化学品",
"液晶取向剂及配套化学品",
"功能湿电子化学品",
"砷化镓",
"氮化镓",
"氮化硅",
"磁性载体",
"研磨液及配套化学品、研磨垫材料",
"电子级酚醛树脂",
"钝化液",
"电镀化学品及配套材料",
"涂胶显影设备",
"硅片研磨机",
"刻蚀机",
"氧化/扩散炉",
"磷化铟",
"氮化铝",
"晶圆检测设备",
"多晶硅切削液"
]

counts = [
3726,2171,1915,1423,1141,1132,1127,1113,1111,1104,1092,1082,813,642,558,555,551,535,
526,520,429,425,419,398,365,351,226,90,30,30,30,30,24,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
18,16,16,10
]

# 检查长度是否一致
if len(names) != len(counts):
    raise ValueError(f"名称数量 ({len(names)}) 与 count 数量 ({len(counts)}) 不一致！")

# 创建 DataFrame
df = pd.DataFrame({"名称": names, "count": counts})

# ====== 定义类别划分规则 ======
def categorize(name):
    if any(x in name for x in ["制造","设计验证"]):
        return "芯片制造与设计"
    elif any(x in name for x in ["晶圆","外延片","硅片","单晶","多晶"]):
        return "晶圆及外延片"
    elif any(x in name for x in ["器件","二极管","晶闸管","晶体管","整流桥"]):
        return "半导体器件"
    elif any(x in name for x in ["衬底"]):
        return "衬底材料"
    elif any(x in name for x in ["液","试剂","化学品","材料","金属有机化合物","活性剂","减水剂","环氧树脂"]):
        return "化学品与材料"
    elif any(x in name for x in ["机","设备","炉","薄膜","测量","光刻"]):
        return "制造设备"
    else:
        return "其他材料与辅助"

# 应用分类
df["类别"] = df["名称"].apply(categorize)

# ====== 按类别统计 ======
stats = df.groupby("类别")["count"].agg(['min','max','mean','median','sum']).reset_index()
stats.rename(columns={
    "min":"最小值",
    "max":"最大值",
    "mean":"均值",
    "median":"中位数",
    "sum":"总和"
}, inplace=True)

# 输出结果
print(stats)

# 如果需要保存为 Excel
stats.to_excel("产业类别统计分析.xlsx", index=False)