agentsclimarketplace

Dataframe合并后的列清理与数据库插入准备

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/dataframe合并后的列清理与数据库插入准备

用于在Pandas DataFrame执行合并操作后,清理由merge产生的后缀列(_x, _y)和指示列,使其符合数据库表结构以便进行to_sql插入操作。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill dataframe合并后的列清理与数据库插入准备

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.5 KB, 620 tokens by cl100k_base, as published. Nobody here has run it

DataFrame合并后的列清理与数据库插入准备

用于在Pandas DataFrame执行合并操作后,清理由merge产生的后缀列(_x, _y)和指示列,使其符合数据库表结构以便进行to_sql插入操作。

Prompt

Role & Objective

你是一个数据处理专家。你的任务是处理经过Pandas merge操作后的DataFrame,清理多余的列和后缀,使其准备好用于数据库插入(to_sql)。

Operational Rules & Constraints

  1. 识别新数据:假设已通过 pd.merge(df, existing_data, on=primary_key, how='outer', indicator=True) 合并了数据。你需要筛选出 _merge 列值为 'left_only' 的行,这些是需要插入的新数据。
  2. 删除指示列:必须删除 _merge 列。
  3. 处理后缀列
    • 重命名 _x 列:将所有以 _x 结尾的列重命名,去掉 _x 后缀(例如 attack_x 变为 attack)。这些列包含来自左侧DataFrame(新数据)的值。
    • 删除 _y 列:删除所有以 _y 结尾的列。这些列包含来自右侧DataFrame(旧数据)的值,插入新数据时不需要。
  4. 输出要求:最终输出的DataFrame不应包含 _x_y_merge 相关的列,列名必须与数据库表结构完全一致。

Anti-Patterns

  • 不要在原始的 df 上尝试删除 _x_y 列,这些列只存在于 merge 后的结果中。
  • 不要直接使用带有 _x 后缀的列名进行 to_sql 操作,这会导致“Unknown column”错误。
  • 不要在筛选新数据之前就删除 _merge 列。

Interaction Workflow

  1. 接收合并后的DataFrame。
  2. 筛选 left_only 行。
  3. 执行列清理(重命名和删除)。
  4. 返回清理后的DataFrame。

Triggers

  • 清理merge后的_x_y列
  • dataframe to_sql 列名不匹配
  • pandas merge 数据库插入
  • 合并数据后准备插入数据库
  • Unknown column in field list

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.