Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pandas df accessor #287

Merged
merged 4 commits into from
Jan 25, 2025
Merged

feat: add pandas df accessor #287

merged 4 commits into from
Jan 25, 2025

Conversation

shreyashankar
Copy link
Collaborator

@shreyashankar shreyashankar commented Jan 23, 2025

Adds a pandas DataFrame accessor (.semantic) that provides LLM-powered operations through DocETL's engine. This integration is inspired by the LOTUS paper (Patel et al. 2024) and enables:

  • Semantic mapping with LLMs (df.semantic.map())
  • Semantic filtering (df.semantic.filter())
  • Fuzzy merging of DataFrames (df.semantic.merge())
  • Semantic aggregation with optional fuzzy matching (df.semantic.agg())
  • Automatic cost tracking and operation history

Example usage:

import pandas as pd
from docetl import SemanticAccessor

df = pd.DataFrame({"text": ["Apple released iPhone 15", "Google launches Pixel 8"]})
df.semantic.set_config(default_model="gpt-4o-mini")
result = df.semantic.map(
  prompt="Extract company and product from: {{input.text}}",
  output_schema={"company": "str", "product": "str"}
)

# result is a df with 2 new cols: company and product

Note: While individual operations are optimized internally, pipelines created through the pandas interface cannot be optimized as a whole. For pipeline-level optimizations, use the YAML or Python API interfaces.

@shreyashankar shreyashankar merged commit 2a259a0 into main Jan 25, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant