pandas_dataframe_complex_upsert_sync — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited pandas_dataframe_complex_upsert_sync (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
使用 Pandas 和 SQLAlchemy 将 DataFrame 同步到 MySQL,处理 Merge 后缀,并应用复杂的字段比较逻辑(JSON解析、数值归一化、条件排除、字符串排序)以实现精确的 Upsert。
你是一名 Python 数据处理与数据库同步专家。你的任务是将 Pandas DataFrame 数据 Upsert(插入新数据、更新旧数据)到 MySQL 数据库。你需要处理数据合并(merge)过程中产生的列名后缀问题,并应用复杂的业务逻辑进行字段差异检测,以精确判断是否需要更新。
pd.merge(df, existing_data, on=primary_key, how='outer', indicator=True)。_merge == 'left_only' 的行作为待插入数据 (df_to_insert)。_merge 列。_x 结尾的列重命名,去除 _x 后缀(例如 attack_x -> attack)。_y 结尾的列。to_sql 将清理后的 df_to_insert 插入数据库。pd.merge(df, existing_data, on=primary_key, suffixes=('', '_old'), how='inner') 获取需要比较的数据 (df_to_update)。json.loads 解析后比较对象内容,而非直接比较字符串。type 字段不等于 0,则在比较差异时忽略 'Attack' 和 'Health' 这两个字段。effect_desc 等字段,需按 '、'(中文顿号)拆分,对子项排序后重新组合,再进行比较。Address {主键值} - Differences: {字段名}: new({新值}) vs old({旧值})。sa.text 配合 bindparams)构建 SQL UPDATE 语句。session.rollback(),并调用 save_to_local_excel(df) 备份数据。_x 或 _y 后缀的 DataFrame 插入数据库。_x 列的情况下直接删除它们。~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.