Skip to main content

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 with genai.GenerativeModel)
  • df: A pandas DataFrame or list of DataFrames
  • verbose: 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 response
  • run(question: str) -> str: Alias for chat()
  • invoke(state: dict) -> dict: Advanced method for custom state handling

Common Issues and Solutions

  1. Import Error: If you get an error about missing dependencies, make sure you have all required packages installed:

    pip install "google-pandas-agent[all]"
    
  2. API Key Error: Make sure to configure your Google API key before creating the model:

    genai.configure(api_key='your-api-key')
    
  3. 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

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)

Source distribution for google-pandas-agent 1.0.3
File Size Uploaded
google_pandas_agent-1.0.3.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for google-pandas-agent 1.0.3
File Interpreter ABI Platform
google_pandas_agent-1.0.3-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page