Skip to main content

Google‑native alternative to LangChain's create_pandas_dataframe_agent

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

google_pandas_agent-1.0.3.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

google_pandas_agent-1.0.3-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file google_pandas_agent-1.0.3.tar.gz.

File metadata

  • Download URL: google_pandas_agent-1.0.3.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for google_pandas_agent-1.0.3.tar.gz
Algorithm Hash digest
SHA256 3f6ef84a44a7b61b5f04cdfce795ba7a2a6b0bfff9cd1dd12d2f67d2f60f2720
MD5 7893e06e60ce867d8ced3b01687b478f
BLAKE2b-256 327e435ae0fb14f9e646f6e169a388a50836f465fb3245ad34d9e31a14003a85

See more details on using hashes here.

File details

Details for the file google_pandas_agent-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for google_pandas_agent-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7da8c652880e2fbb5b596bb4ad810d55b30e2797abff8889cef919dc16beb072
MD5 dbfab8f793c39000f760b04a86667b18
BLAKE2b-256 e2442ffd0c25b301c000d5ac2ba0c77177dc9ff5d53063dfd727baaa9444e001

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page