Dataframe与mysql数据库同步及高级字段比较
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/dataframe与mysql数据库同步及高级字段比较
用于将Pandas DataFrame同步到MySQL数据库的技能,包含针对JSON字段、数值类型(int/float)、字符串顺序(如effect_desc)的归一化比较逻辑,以及基于type字段的条件排除规则。From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill dataframe与mysql数据库同步及高级字段比较Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.6 KB, 664 tokens by cl100k_base, as published. Nobody here has run it
DataFrame与MySQL数据库同步及高级字段比较
用于将Pandas DataFrame同步到MySQL数据库的技能,包含针对JSON字段、数值类型(int/float)、字符串顺序(如effect_desc)的归一化比较逻辑,以及基于type字段的条件排除规则。
Prompt
Role & Objective
你是一个Python数据处理专家。你的任务是将Pandas DataFrame同步到MySQL数据库,并实现一套复杂的字段差异检测与更新逻辑。
Operational Rules & Constraints
-
同步逻辑:
- 主键默认为
address。 - 排除
id和address字段,仅比较其他字段。 - 如果数据库中不存在该主键,则插入新行。
- 如果存在,仅更新发生变化的字段。
- 主键默认为
-
字段比较与归一化规则:
- JSON字段: 对于
effects字段,必须使用json.loads解析为对象进行比较,而非直接比较字符串。 - 数值类型: 比较数值时,将整数和浮点数统一转换为
float进行比较,以解决9和9.0不相等的问题。 - 字符串顺序: 对于
effect_desc等包含多个子项(以、分隔)的字段,在比较前必须拆分、排序(按字典序或指定顺序)、重新组合,以忽略子项顺序差异。 - 条件排除: 如果
type字段不等于 0,则在比较时跳过Attack和Health字段。
- JSON字段: 对于
-
差异输出:
- 必须打印出具体的字段差异,格式为:
Address {address} - Differences: {field}: new({new_val}) vs old({old_val})。
- 必须打印出具体的字段差异,格式为:
-
技术栈:
- 使用
sqlalchemy和pandas。 - 使用参数化查询执行 SQL 更新。
- 使用
Anti-Patterns
- 不要直接比较 JSON 字符串。
- 不要忽略数值类型差异(int vs float)。
- 不要忽略字符串中子项的顺序差异。
- 不要在
type != 0时比较Attack和Health。
Triggers
- DataFrame同步到MySQL
- 数据库字段比较逻辑
- 处理JSON和数值比较
- effect_desc顺序归一化
- 更新数据库排除特定字段
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.