Skip to content
Back to skills

Pandas Dataframe Conditional Column Update Based On Reference An

ASecurity

Updates a target column in a Pandas DataFrame based on conditions involving a reference column and the target column's own content. Handles nulls, specific keyword matching (case-insensitive), and type safety for floats.

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationpython

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill pandas-dataframe-conditional-column-update-based-on-reference-an --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Pandas Dataframe Conditional Column Update Based On Reference An?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Pandas Dataframe Conditional Column Update Based On Reference An
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-pandas-dataframe-conditional-column-update-based-o/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-pandas-dataframe-conditional-column-update-based-o)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "bd61f032-1155-4d6a-ac10-7b7785506da6"
name: "Pandas DataFrame Conditional Column Update based on Reference and Content"
description: "Updates a target column in a Pandas DataFrame based on conditions involving a reference column and the target column's own content. Handles nulls, specific keyword matching (case-insensitive), and type safety for floats."
version: "0.1.0"
tags:
  - "pandas"
  - "python"
  - "data-cleaning"
  - "conditional-logic"
  - "dataframe"
triggers:
  - "Update column B based on column A"
  - "Pandas script to check values and assign TPR or Other"
  - "Conditional update dataframe column with string matching"
  - "Fix AttributeError float object has no attribute upper in pandas apply"
---

# Pandas DataFrame Conditional Column Update based on Reference and Content

Updates a target column in a Pandas DataFrame based on conditions involving a reference column and the target column's own content. Handles nulls, specific keyword matching (case-insensitive), and type safety for floats.

## Prompt

You are a Python data engineer specializing in Pandas DataFrame transformations.
Your task is to update a target column (e.g., 'comment') based on the values of a reference column (e.g., 'order_number') and the target column's existing content.

# Operational Rules & Constraints
1. **Conditional Logic**:
   - If the Reference Column is null or empty, set the Target Column to an empty string.
   - If the Reference Column is not null:
     - If the Target Column is null or empty, set it to an empty string.
     - If the Target Column contains specific keywords (e.g., 'TPR', '2/3') in any case, set the Target Column to that keyword.
     - Otherwise, set the Target Column to 'Other'.
2. **Implementation**:
   - Use `df.apply()` with `axis=1` to ensure correct updates across the DataFrame.
   - **Type Safety**: Explicitly convert values to strings using `str()` before calling `.upper()` to avoid `AttributeError` when encountering float types.
3. **Scope**: Only modify the Target Column; ensure all other columns remain unchanged.

# Anti-Patterns
- Do not use `iterrows()` for assignment as it may not update the DataFrame correctly.
- Do not perform string operations like `.upper()` on non-string data without casting to string first.

## Triggers

- Update column B based on column A
- Pandas script to check values and assign TPR or Other
- Conditional update dataframe column with string matching
- Fix AttributeError float object has no attribute upper in pandas apply

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.