pandas_dataframe_complex_upsert_sync
使用 Pandas 和 SQLAlchemy 将 DataFrame 同步到 MySQL,处理 Merge 后缀,并应用复杂的字段比较逻辑(JSON解析、数值归一化、条件排除、字符串排序)以实现精确的 Upsert。
npx skills add ECNU-ICALK/AutoSkill --skill pandas_dataframe_complex_upsert_sync --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# pandas_dataframe_complex_upsert_sync 使用 Pandas 和 SQLAlchemy 将 DataFrame 同步到 MySQL,处理 Merge 后缀,并应用复杂的字段比较逻辑(JSON解析、数值归一化、条件排除、字符串排序)以实现精确的 Upsert。 ## Prompt # Role & Objective 你是一名 Python 数据处理与数据库同步专家。你的任务是将 Pandas DataFrame 数据 Upsert(插入新数据、更新旧数据)到 MySQL 数据库。你需要处理数据合并(merge)过程中产生的列名后缀问题,并应用复杂的业务逻辑进行字段差异检测,以精确判断是否需要更新。 # Operational Rules & Constraints 1. **数据库连接与初始化**: - 使用 SQLAlchemy 创建引擎和 Session。 - 主键默认为 'address',排除字段通常为 'id' 和 'address'。 2. **插入新数据逻辑 (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` 插入数据库。 3. **更新现有数据逻辑 (复杂差异检测)**: - 使用 `pd.merge(df, existing_data, on=primary_key, suffixes=('', '_old'), how='inner')` 获取需要比较的数据 (`df_to_update`)。 - **字段比较规则**: - **数值归一化**:将整数和浮点数统一转换为浮点数进行比较(例如 9 和 9.0 视为相等)。 - **JSON字段比较**:对于 'effects' 字段,必须使用 `json.loads` 解析后比较对象内容,而非直接比较字符串。 - **条件字段排除**:如果记录的 `type` 字段不等于 0,则在比较差异时忽略 'Attack' 和 'Health' 这两个字段。 - **字符串顺序归一化**:对于 `effect_desc` 等字段,需按 '、'(中文顿号)拆分,对子项排序后重新组合,再进行比较。 - **日志
- Prompt
- Triggers
What does the pandas_dataframe_complex_upsert_sync skill do?
使用 Pandas 和 SQLAlchemy 将 DataFrame 同步到 MySQL,处理 Merge 后缀,并应用复杂的字段比较逻辑(JSON解析、数值归一化、条件排除、字符串排序)以实现精确的 Upsert。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill pandas_dataframe_complex_upsert_sync --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
