An intelligent AI-powered data cleaning agent built with CrewAI and Pandas MCP Server integration. This agent automatically loads, cleans, analyzes, and saves datasets from various formats including CSV, Excel, JSON, and SQL databases.
- 🤖 AI-Powered Cleaning: Uses Google Gemini 2.0 Flash for intelligent data cleaning decisions
- 📁 Multiple Format Support: Works with CSV, Excel (XLSX/XLS), JSON, and SQL databases
- 🧹 Automatic Cleaning: Removes nulls, duplicates, and handles outliers
- 💬 Interactive Queries: Ask questions about your data during the cleaning process
- 💾 Auto-Save: Automatically saves cleaned data in a
cleaned/folder - 🔧 MCP Integration: Leverages Pandas MCP Server tools for robust data operations
- Python 3.12 or higher
- Google Gemini API key
- Pandas MCP Server (included in this project)
git clone https://github.com/KNIHAL/pandas-agent.git
cd pandas-agentpip install -r requirements.txtCreate a .env file in the project root:
GOOGLE_API_KEY=your_gemini_api_key_hereOr the agent will prompt you to enter the API key when you run it.
Ensure server.py (Pandas MCP Server) is in the same directory as agent.py.
User Input → CrewAI Agent → Pandas MCP Server → Data Processing → Cleaned Output
- User provides file path (CSV, Excel, JSON, or SQL connection)
- Agent loads data using MCP tools
- Agent analyzes and identifies data quality issues
- Agent cleans data:
- Removes null/missing values
- Eliminates duplicate rows
- Handles outliers
- Agent answers queries about the dataset
- Agent saves cleaned data to
cleaned/folder
Role: Data Cleaning Agent
Goal: Load, clean, analyze, and save datasets
Capabilities:
- Read CSV, Excel, JSON files
- Connect to SQL databases
- Remove nulls and duplicates
- Handle outliers intelligently
- Answer data-related queries
- Save cleaned datasets
LLM: Google Gemini 2.0 Flash (Temperature: 0.1 for consistent results)
python agent.pyThe agent will prompt you:
Enter path to your data file (CSV / Excel):
python agent.py
# Input: /path/to/sales_data.csvAgent will:
- Load the CSV file
- Identify and remove null values
- Remove duplicate rows
- Detect and handle outliers
- Save cleaned file to
cleaned/sales_data_cleaned.csv
python agent.py
# Input: /path/to/customer_data.xlsxAgent handles:
- Multiple sheets (if present)
- Mixed data types
- Date formatting issues
- Missing values
python agent.py
# Input: /path/to/transactions.jsonAgent processes:
- Nested JSON structures
- Array data
- Type conversions
python agent.py
# Input: sqlite:///mydata.db
# (You can also provide specific SQL queries)Edit agent.py to modify agent parameters:
pandas_agent = Agent(
role="Data Cleaning Agent",
goal="Your custom goal here",
backstory="Your custom backstory",
tools=tools,
reasoning=True, # Enable reasoning mode
verbose=True, # Show detailed logs
allow_code_execution=True, # Allow pandas code execution
)processing_task = Task(
description="Your custom cleaning workflow",
expected_output="Expected output format",
agent=pandas_agent,
markdown=True,
)llm = LLM(
api_key=os.getenv("GOOGLE_API_KEY"),
model="gemini/gemini-2.0-flash", # or "gemini/gemini-pro"
temperature=0.1, # Adjust for creativity vs consistency
)The agent provides a structured markdown response including:
- Number of null values removed
- Number of duplicate rows eliminated
- Outlier treatment details
- Data type conversions performed
- Path to cleaned file
- File format and size
- Number of rows and columns
- Column names and types
- Responses to any questions asked during cleaning
- Statistical summaries
- Data insights
The agent has access to all Pandas MCP Server tools:
- read_metadata_tool: Analyze file structure
- run_pandas_code_tool: Execute pandas operations
- read_json_tool: Load JSON files
- dataframe_to_json_tool: Save to JSON
- read_sql_tool: Query databases
- dataframe_to_sql_tool: Save to database
- generate_chartjs_tool: Create visualizations
pandas-data-cleaning-agent/
│
├── agent.py # Main CrewAI agent
├── server.py # Pandas MCP Server
├── core/ # MCP Server core modules
│ ├── config.py
│ ├── metadata.py
│ ├── execution.py
│ └── visualization.py
├── cleaned/ # Output folder (auto-created)
├── .env # Environment variables
├── requirements.txt # Python dependencies
└── README.md # This file
- Code Execution Safety: MCP Server blocks dangerous operations (os, sys, exec, eval)
- Input Validation: File paths and SQL queries are validated
- API Key Protection: API keys stored in
.envfile (never commit to git)
1. "Module not found" error
pip install crewai crewai-tools python-dotenv2. "MCP Server not found"
- Ensure
server.pyis in the same directory asagent.py - Check file permissions:
chmod +x server.py
3. "API key invalid"
- Verify your Google Gemini API key in
.env - Get a new key from: https://makersuite.google.com/app/apikey
4. "File not found" error
- Use absolute paths:
/full/path/to/file.csv - Check file permissions and existence
5. "Python version mismatch"
- Ensure Python 3.12+ is installed
- Update
UV_PYTHONinagent.pyif needed
Input: sales_2024.csv with 10,000 rows, 15 columns
Issues: 500 null values, 120 duplicates, pricing outliers
Agent Actions:
- Loaded CSV file
- Removed 500 rows with critical nulls
- Eliminated 120 duplicate transactions
- Capped price outliers at 99th percentile
- Saved cleaned file with 9,380 rows
Output: cleaned/sales_2024_cleaned.csv
Input: Excel file with multiple sheets
Issues: Mixed data types, date format inconsistencies
Agent Actions:
- Processed all sheets
- Standardized date formats
- Converted string numbers to numeric
- Merged clean data
- Saved as unified CSV
Contributions are welcome! Feel free to:
- Report bugs
- Suggest features
- Submit pull requests
MIT License - see LICENSE file for details
- CrewAI: For the amazing agent framework
- Pandas MCP Server: For robust data handling tools
- Google Gemini: For powerful AI capabilities
For issues or questions:
- Open an issue on GitHub
- Check existing issues and discussions
- ✅ Initial release
- ✅ CSV, Excel, JSON, SQL support
- ✅ Automatic cleaning (nulls, duplicates, outliers)
- ✅ Interactive query support
- ✅ Auto-save functionality
- ✅ Google Gemini 2.0 Flash integration
- ✅ CrewAI agent implementation
- ✅ Pandas MCP Server integration
- Add data visualization dashboard
- Support for more file formats (Parquet, Avro)
- Custom cleaning rules configuration
- Multi-agent collaboration for complex datasets
- Web UI for easier interaction
- Scheduled cleaning jobs
- Data quality scoring system
Made with ❤️ using CrewAI and Pandas MCP Server