Google Pandas Agent
A Google-native alternative to LangChain's create_pandas_dataframe_agent, powered by Google's Gemini models and LangGraph.
Features
- Query pandas DataFrames using natural language
- Powered by Google's Gemini models
- Simple, intuitive interface
- Type-safe implementation
- Comprehensive error handling
- Support for multiple DataFrames
Installation
pip install google-pandas-agent
Requirements
- Python >= 3.10
- pandas >= 2.2
- google-generativeai >= 0.8.5
- langgraph >= 0.3.21
Quick Start
import pandas as pd
import google.generativeai as genai
from google_pandas_agent import create_pandas_dataframe_agent
# Initialize Gemini
genai.configure(api_key='your-api-key') # Get your API key from Google Cloud Console
model = genai.GenerativeModel('gemini-pro')
# Create a sample DataFrame
df = pd.DataFrame({
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'City': ['New York', 'London', 'Paris']
})
# Create the agent
agent = create_pandas_dataframe_agent(model, df)
# Ask questions about your data
response = agent.chat("What is the average age?")
print(response)
# You can also use multiple DataFrames
df2 = pd.DataFrame({
'City': ['New York', 'London', 'Paris'],
'Country': ['USA', 'UK', 'France']
})
agent = create_pandas_dataframe_agent(model, [df, df2])
response = agent.chat("Show me people's names along with their countries")
print(response)
API Reference
create_pandas_dataframe_agent
def create_pandas_dataframe_agent(
llm: genai.GenerativeModel,
df: Union[pd.DataFrame, List[pd.DataFrame]],
*,
verbose: bool = False,
allow_dangerous_code: bool = False,
**kwargs,
) -> AgentExecutor
Creates an agent that can answer questions about pandas DataFrames.
Parameters
llm: A Gemini model instance (must be initialized withgenai.GenerativeModel)df: A pandas DataFrame or list of DataFramesverbose: Enable verbose output (default: False)allow_dangerous_code: Allow potentially unsafe imports in the Python REPL (default: False)**kwargs: Additional arguments passed to the executor
Returns
An AgentExecutor instance that can process natural language queries about the DataFrame(s)
AgentExecutor
The main class for executing queries against DataFrames.
Methods
chat(question: str) -> str: Process a natural language query and return the responserun(question: str) -> str: Alias for chat()invoke(state: dict) -> dict: Advanced method for custom state handling
Common Issues and Solutions
-
Import Error: If you get an error about missing dependencies, make sure you have all required packages installed:
pip install "google-pandas-agent[all]"
-
API Key Error: Make sure to configure your Google API key before creating the model:
genai.configure(api_key='your-api-key')
-
Model Error: Ensure you're using the correct model name ('gemini-pro'):
model = genai.GenerativeModel('gemini-pro')
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Authors
- Ariamehr Maleki (ariamehr.mai@gmail.com)
- Frank Roh (frankagilepm@gmail.com)
- Darren North (denorth222@gmail.com)
Metadata
Release files for google-pandas-agent 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| google_pandas_agent-1.0.3.tar.gz | 8.4 kB | Without provenance | Details for google_pandas_agent-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| google_pandas_agent-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for google_pandas_agent-1.0.3-py3-none-any.whl |
Total release size: 17.0 kB
Release files / google_pandas_agent-1.0.3.tar.gz
| Download URL | google_pandas_agent-1.0.3.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f6ef84a44a7b61b5f04cdfce795ba7a2a6b0bfff9cd1dd12d2f67d2f60f2720
|
|
BLAKE2b-256 checksum How to use checksums |
327e435ae0fb14f9e646f6e169a388a50836f465fb3245ad34d9e31a14003a85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.2
|
Release files / google_pandas_agent-1.0.3-py3-none-any.whl
| Download URL | google_pandas_agent-1.0.3-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7da8c652880e2fbb5b596bb4ad810d55b30e2797abff8889cef919dc16beb072
|
|
BLAKE2b-256 checksum How to use checksums |
e2442ffd0c25b301c000d5ac2ba0c77177dc9ff5d53063dfd727baaa9444e001
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.2
|
Security for google-pandas-agent 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.