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 locationfind_min_value_location- Global min value and locationget_column_max/min/sum/mean/median/std- Column statisticscount_rows/columns/unique- Countsfilter_by_value/comparison- Row filteringfilter_and_aggregate- Filter then aggregate (e.g., "average salary for engineers")group_aggregate- Group by and aggregateget_correlation- Correlation between columnsget_top_n_rows/bottom_n_rows- Top/bottom N rows- And more...
Tests
pip install -e ".[dev]"
pytest
Project details
Release history Release notifications | RSS feed
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.1.tar.gz
(15.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
ponia-0.1.1-py3-none-any.whl
(12.0 kB
view details)
File details
Details for the file ponia-0.1.1.tar.gz.
File metadata
- Download URL: ponia-0.1.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e7b8510cb327d8a18d729036cf66f1cf1dd06a4353e48662008067f260957c6
|
|
| MD5 |
e4050fe7fa44fcbc404b7c1c526e3ce4
|
|
| BLAKE2b-256 |
c07627ec6046239bde2c16d38c98d28846530c2a24c2e7e9d72753834dac6283
|
File details
Details for the file ponia-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ponia-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2462c068984ec3d294242e018f8f916cb6f3542e7f2c14a6d5abe8eb4c301db
|
|
| MD5 |
373c4ff4ecf21b7bf958002dd11ba7d4
|
|
| BLAKE2b-256 |
a192b2f09e48dc86001e5b5b820f39c502745ec42ce4507c5b9b92d8385fbb31
|