Pandas Agent
Pandas data manipulation tools for AI agents.
Prerequisites
- Python 3.10 or higher
- PraisonAI Agents package installed
pandas
package installed
Pandas Tools
Use Pandas Tools to manipulate and analyze data with AI agents.
Install Dependencies
First, install the required packages:
Import Components
Import the necessary components:
Create Agent
Create a data analysis agent:
Define Task
Define the analysis task:
Run Agent
Initialize and run the agent:
Understanding Pandas Tools
What are Pandas Tools?
Pandas Tools provide data analysis capabilities for AI agents:
- Data filtering and selection
- Statistical analysis
- Data transformation
- Group operations
- Pivot table creation
Key Components
Data Agent
Create specialized data agents:
Analysis Task
Define analysis tasks:
Process Types
Sequential or parallel processing:
Analysis Options
Customize analysis parameters:
Available Functions
Function Details
read_csv(filepath: str, **kwargs)
Reads CSV files into pandas DataFrames:
- Flexible data import
- Error handling
- Additional pandas options
read_excel(filepath: str, **kwargs)
Reads Excel files into pandas DataFrames:
- Multiple sheet support
- Error handling
- Additional pandas options
write_csv(df: pd.DataFrame, filepath: str, **kwargs)
Writes DataFrames to CSV files:
- Directory creation
- Error handling
- Formatting options
write_excel(df: pd.DataFrame, filepath: str, **kwargs)
Writes DataFrames to Excel files:
- Directory creation
- Error handling
- Excel-specific options
filter_data(df: pd.DataFrame, query: str)
Filters DataFrames using query strings:
- SQL-like syntax
- Complex conditions
- Efficient filtering
get_summary(df: pd.DataFrame)
Generates comprehensive data summaries:
- Basic statistics
- Data types
- Memory usage
- Null counts
group_by(df: pd.DataFrame, columns: Union[str, List[str]], agg_dict: Dict[str, Union[str, List[str]]])
Groups and aggregates data:
- Multiple grouping columns
- Multiple aggregations
- Custom functions
pivot_table(df: pd.DataFrame, index: Union[str, List[str]], columns: Optional[Union[str, List[str]]] = None, values: Optional[Union[str, List[str]]] = None, aggfunc: str = “mean”)
Creates pivot tables:
- Multiple index levels
- Column pivoting
- Custom aggregations
- Flexible reshaping
Example Agent Configuration
Dependencies
The pandas tools require the following Python packages:
- pandas: For data manipulation and analysis
- numpy: For numerical operations (automatically installed with pandas)
- openpyxl: For Excel file support (optional)
These will be automatically installed when needed.
Error Handling
All functions include comprehensive error handling:
- File I/O errors
- Data format errors
- Query syntax errors
- Memory errors
Errors are handled consistently:
- File operations return bool for success/failure
- Data operations return error details in result
- All errors are logged for debugging
Common Use Cases
- Data Analysis:
- Sales Reporting:
- Data Transformation:
Examples
Basic Data Analysis Agent
Advanced Data Operations with Multiple Agents
Best Practices
Common Patterns
Data Analysis Pipeline
Was this page helpful?