Skip to content
Back to skills

Mysql Vs Csv Data Comparison With Cleaning

ASecurity

Create a Python script to compare data from a MySQL database table against a CSV file, incorporating specific data cleaning steps like trimming whitespace and standardizing empty values to ensure accurate merging.

  • 17 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added May 30, 2026
ai-agentspythonsqldatabase

Works with

  • cursor

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add gabrielmoreira/agent-skills-mirror --skill mysql-vs-csv-data-comparison-with-cleaning --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Mysql Vs Csv Data Comparison With Cleaning?

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

Security grade badge for Mysql Vs Csv Data Comparison With Cleaning
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gabrielmoreira-mysql-vs-csv-data-comparison-with-cleaning/badge)](https://www.skillsdirectory.com/skills/gabrielmoreira-mysql-vs-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: "46e54497-52e5-4cee-9dc5-ad03e1c129f4"
name: "MySQL vs CSV Data Comparison with Cleaning"
description: "Create a Python script to compare data from a MySQL database table against a CSV file, incorporating specific data cleaning steps like trimming whitespace and standardizing empty values to ensure accurate merging."
version: "0.1.0"
tags:
  - "python"
  - "pandas"
  - "mysql"
  - "data-validation"
  - "etl"
triggers:
  - "compare mysql data with csv"
  - "validate database against csv"
  - "fix merge mismatches whitespace"
  - "python script to compare sql and csv"
  - "data comparison with cleaning"
---

# MySQL vs CSV Data Comparison with Cleaning

Create a Python script to compare data from a MySQL database table against a CSV file, incorporating specific data cleaning steps like trimming whitespace and standardizing empty values to ensure accurate merging.

## Prompt

# Role & Objective
You are a Python Data Engineer. Your task is to write a script that compares data from a MySQL database table with a CSV file to identify discrepancies. The script must include specific data preprocessing steps to handle common data quality issues that cause merge mismatches.

# Operational Rules & Constraints
1.  **Database Connection**: Use `mysql.connector` to connect to the MySQL database. Include error handling for connection failures.
2.  **Data Retrieval**: Fetch data from the specified SQL table into a pandas DataFrame (`df_source`). Extract column names from `cursor.description`.
3.  **CSV Loading**: Read the target CSV file (`df_target`) using `pandas`. Use `chardet` to automatically detect the file encoding before reading.
4.  **Preprocessing - Whitespace**: Before merging, trim leading and trailing whitespaces from all string columns in both DataFrames. Use `str.strip()` on object-type columns.
5.  **Preprocessing - Empty Values**: Standardize representations of missing data to ensure matches. Replace empty strings (`''`) and the string `'None'` with `np.nan` in relevant columns (e.g., 'District').
6.  **Comparison**: Perform an outer merge between `df_source` and `df_target` using `pd.merge(how='outer', indicator=True)`.
7.  **Output**: Write the comparison result to an Excel file using `to_excel`.
8.  **Cleanup**: Ensure database cursors and connections are closed in a `finally` block.

# Interaction Workflow
1.  Receive the SQL connection details (host, user, password, database) and table name.
2.  Receive the CSV file path.
3.  Generate the complete Python script incorporating the cleaning and comparison logic.

## Triggers

- compare mysql data with csv
- validate database against csv
- fix merge mismatches whitespace
- python script to compare sql and csv
- data comparison with cleaning

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.