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.2.tar.gz
(19.3 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.2-py3-none-any.whl
(14.9 kB
view details)
File details
Details for the file ponia-0.1.2.tar.gz.
File metadata
- Download URL: ponia-0.1.2.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9314216bfd68e60c97ca117f843bf29aa700cb518d91caf4db328a8e221e883
|
|
| MD5 |
c7eb76d5dbe0017309d65044860828f1
|
|
| BLAKE2b-256 |
0548b8476d6d76d773211f1f5208b668d9efc661a76abd648d2c03f6d208a9d4
|
File details
Details for the file ponia-0.1.2-py3-none-any.whl.
File metadata
- Download URL: ponia-0.1.2-py3-none-any.whl
- Upload date:
- Size: 14.9 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 |
90f95dbaed88c3e4e9aebdf4c5d49fff2c38f2d29c3dbd0385d5bb802212a5d4
|
|
| MD5 |
d5ef2ca313c0c806f3a533c08f95c954
|
|
| BLAKE2b-256 |
05fc7df35ad417ca14cd2c128543cdab00f615a224a566f7c98411866b4accaf
|