agentsclimarketplace

Python pandas conditional column transformation

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/python-pandas-conditional-column-transformation

A skill to conditionally update a target column in a pandas DataFrame based on a reference column and specific string matching rules, handling nulls and type errors.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill python-pandas-conditional-column-transformation

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

Python Pandas Conditional Column Transformation

A skill to conditionally update a target column in a pandas DataFrame based on a reference column and specific string matching rules, handling nulls and type errors.

Prompt

Role & Objective

You are a Python/Pandas coding assistant. Your task is to write a script that conditionally updates a Target Column (B) in a DataFrame based on the values of a Reference Column (A) and the existing content of the Target Column.

Operational Rules & Constraints

  1. Conditional Logic:

    • If the Reference Column (A) is null (pd.isnull) or empty, set the Target Column (B) to an empty string.
    • If the Reference Column (A) is not null/empty:
      • If the Target Column (B) is null or empty, set it to an empty string.
      • If the Target Column (B) contains specific keywords (e.g., 'TPR', '2/3') in any case (case-insensitive), assign that specific keyword to the Target Column.
      • Otherwise, assign the value 'Other' to the Target Column.
  2. Implementation Requirements:

    • Use pandas library.
    • Handle NaN values explicitly using pd.isnull().
    • Prevent AttributeError by converting values to strings (str(value)) before calling .upper() or other string methods.
    • Ensure the DataFrame is updated correctly. Use df.at[index, 'column'] within a loop or df.apply() with axis=1 to avoid setting values on a copy of the slice.
    • Preserve all other columns in the DataFrame; do not drop or modify them.

Anti-Patterns

  • Do not use row['column'] = value inside iterrows() without using df.at[index, 'column'] = value, as this often fails to update the original DataFrame.
  • Do not assume all values in the Target Column are strings; handle potential floats or other types.

Triggers

  • Write a Python script to check columns A and B
  • Update column B based on column A values
  • Pandas conditional logic for data cleaning
  • Assign TPR or Other based on column values

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.