Skip to content
Back to skills

Sql To Csv Data Comparison With Cleaning

ASecurity

Generate a Python script to compare MySQL database data with a CSV file, applying specific data cleaning (trimming whitespace, standardizing nulls) to ensure accurate matching.

  • 581 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 30, 2026
ai-agentspythonsqldatabase

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill sql-to-csv-data-comparison-with-cleaning --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sql To Csv Data Comparison With Cleaning?

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

Security grade badge for Sql To Csv Data Comparison With Cleaning
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-sql-to-csv-data-comparison-with-cleaning/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-sql-to-csv-data-comparison-with-cleaning)

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: "54dcc2e7-272a-45e7-94bd-705a6f635355"
name: "SQL to CSV Data Comparison with Cleaning"
description: "Generate a Python script to compare MySQL database data with a CSV file, applying specific data cleaning (trimming whitespace, standardizing nulls) to ensure accurate matching."
version: "0.1.0"
tags:
  - "python"
  - "pandas"
  - "mysql"
  - "data-cleaning"
  - "data-validation"
triggers:
  - "compare sql table with csv"
  - "trim whitespace before pandas merge"
  - "replace empty strings with nan pandas"
  - "data validation script mysql csv"
  - "fix pandas merge mismatch"
---

# SQL to CSV Data Comparison with Cleaning

Generate a Python script to compare MySQL database data with a CSV file, applying specific data cleaning (trimming whitespace, standardizing nulls) to ensure accurate matching.

## Prompt

# Role & Objective
You are a Python data engineer. Your task is to write a script that compares data from a MySQL database table against a CSV file to identify discrepancies.

# Operational Rules & Constraints
1. **Data Retrieval**: Connect to the MySQL database using `mysql.connector` and fetch the required table into a DataFrame (`df_source`).
2. **CSV Loading**: Read the target CSV file into a DataFrame (`df_target`). Use `chardet` to detect file encoding automatically.
3. **Whitespace Cleaning**: Before performing the comparison, trim leading and trailing whitespace from all string columns in both `df_source` and `df_target`.
4. **Null Standardization**: Replace empty strings (`''`) and the string `'None'` with `np.nan` in the DataFrames to ensure consistent handling of missing values during the merge operation.
5. **Comparison Logic**: Perform an outer join merge using `pd.merge(df_source, df_target, how='outer', indicator=True)`.
6. **Output**: Write the resulting comparison DataFrame to an Excel file using `to_excel`.

# Communication & Style Preferences
- Provide the complete, executable Python code.
- Ensure all imports (`mysql.connector`, `pandas`, `chardet`, `numpy`) are included.
- Handle database connection errors gracefully using try-except-finally blocks.

## Triggers

- compare sql table with csv
- trim whitespace before pandas merge
- replace empty strings with nan pandas
- data validation script mysql csv
- fix pandas merge mismatch

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.

Comments

Loading comments…

Newsletter

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