问题我有三个文件字段名都一样如果不重复就union到一起如果有重复按类型优先级取唯一值用python实现import pandas as pd from datetime import date import time todaystr(date.today()) filepath/Users/kangyongqing/Documents/kangyq/202207/课消管理看板/2023Q3课消/亚欧课消11月/课消定标方案新版/202604课消定标/ file1/Users/kangyongqing/Documents/kangyq/202207/课消管理看板/2023Q3课消/亚欧课消11月/课消定标方案新版/202604课消定标/课消定标方案新版2026-03-25.xlsx file2/Users/kangyongqing/Documents/kangyq/202207/课消管理看板/2023Q3课消/亚欧课消11月/课消定标方案新版/202604课消定标/4月基地定标/课消定标方案新版-基地2026-03-30.xlsx file3/Users/kangyongqing/Documents/kangyq/202207/课消管理看板/2023Q3课消/亚欧课消11月/课消定标方案新版/202604课消定标/4月新兼职定标/课消定标方案新版-新兼职2026-03-30.xlsx df1pd.read_excel(file1,usecols[student_user_id, real_name, age,最终标值]) df1[type]大盘 print(df1.head(2)) df2pd.read_excel(file2,usecols[student_user_id, real_name, age,最终标值]) df2[type]基地 print(df2.head(2)) df3pd.read_excel(file3,usecols[student_user_id, real_name, age,最终标值]) df3[type]新兼职 print(df3.head(2)) df_allpd.concat([df1,df2,df3],ignore_indexTrue) print(df_all.head()) # 定义优先级映射数字越小优先级越高 priority_map { 基地: 1, 新兼职: 2, 大盘: 3 } # 定义去重函数按优先级取唯一值 def dedup_by_priority(df, key_colstudent_user_id, priority_coltype): # 添加优先级数值列 df[priority_num] df[priority_col].map(priority_map) # 按 key_col 分组取 priority_num 最小的行 df_dedup df.loc[df.groupby(key_col)[priority_num].idxmin()] # 删除临时列 df_dedup df_dedup.drop(columns[priority_num]) return df_dedup # 执行去重 result dedup_by_priority(df_all, key_colstudent_user_id, priority_coltype) result[student_user_id]result[student_user_id].astype(int64).astype(str) # 输出结果 result.to_excel(filepathf课消定标方案dm库上传取唯一值{today}.xlsx, indexFalse) print(去重合并完成)结果展示