Skip to main content

Query pandas DataFrames with natural language using OpenAI function calling

Project description

Ponia

Query pandas DataFrames with natural language using OpenAI function calling.

Installation

pip install -e .

Usage

import pandas as pd
from ponia import ponia

# Set your API key as environment variable
# export OPENAI_API_KEY="your-api-key"

df = pd.DataFrame({
    'product': ['apple', 'banana', 'orange'],
    'monday': [10, 15, 8],
    'tuesday': [12, 18, 9],
    'wednesday': [8, 20, 11]
})

# Query in natural language
answer = ponia(df, "Which column has the largest value?")
print(answer)
# "The column 'wednesday' has the largest value, which is 20..."

answer = ponia(df, "What is the average of monday sales?")
print(answer)
# "The average of column 'monday' is 11.0"

# Get raw JSON result instead of natural language
result = ponia(df, "What is the max value?", raw=True)
print(result)
# {'value': 20, 'column': 'wednesday', 'row': 1}

Features

  • Zero data leakage: Data is never sent to OpenAI, only the question
  • No eval(): Does not execute AI-generated code, only predefined functions
  • Minimal: Minimal dependencies (pandas, openai)
  • Extensible: Easy to add new functions

Available Functions

  • find_max_value_location - Global max value and location
  • find_min_value_location - Global min value and location
  • get_column_max/min/sum/mean/median/std - Column statistics
  • count_rows/columns/unique - Counts
  • filter_by_value/comparison - Row filtering
  • filter_and_aggregate - Filter then aggregate (e.g., "average salary for engineers")
  • group_aggregate - Group by and aggregate
  • get_correlation - Correlation between columns
  • get_top_n_rows/bottom_n_rows - Top/bottom N rows
  • And more...

Tests

pip install -e ".[dev]"
pytest

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

ponia-0.1.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

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

ponia-0.1.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file ponia-0.1.0.tar.gz.

File metadata

  • Download URL: ponia-0.1.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for ponia-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dcaf11d1e8cac0568094df02f3a60476a57b0a1477f99cb2599bd69961898a73
MD5 04bf37bc0fc3a6bb7b88f5f724a01781
BLAKE2b-256 3e210a4559e3da6510b39da5852f700039d11f6c52f126d4359d1cd6cb0859bd

See more details on using hashes here.

File details

Details for the file ponia-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ponia-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for ponia-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 629c4a7bf9436b080418d56922e7a3d3348d7842da4bf65335e814a95249949c
MD5 de7305945bec76126d07d1bae1d12afb
BLAKE2b-256 cbe8beaa81e81db4605b137e09c0cdb69ee790ecbe35f15df81eee3116fd2f29

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