Basic Usage¶
Practical examples for common use cases.
dataframeit() writes the results and the status into the pandas DataFrame it receives; see Input modified in place. That is why the examples on this page pass df.copy(): without the copy, each example would find the df already processed by the previous one.
Sentiment Analysis¶
from pydantic import BaseModel, Field
from typing import Literal
import pandas as pd
from dataframeit import dataframeit
class Sentiment(BaseModel):
sentiment: Literal['positive', 'negative', 'neutral']
confidence: Literal['high', 'medium', 'low']
df = pd.DataFrame({
'text': [
'Love this product!',
'Terrible, do not recommend.',
'Average, nothing special.'
]
})
result = dataframeit(df.copy(), Sentiment, "Analyze the sentiment of the text.")
Category Classification¶
from pydantic import BaseModel, Field
from typing import Literal
class Category(BaseModel):
category: Literal['technology', 'health', 'finance', 'education', 'other']
subcategory: str = Field(description="More specific subcategory")
result = dataframeit(
df.copy(),
Category,
"Classify the text into the most appropriate category."
)
Entity Extraction¶
from pydantic import BaseModel, Field
from typing import List, Optional
class Entities(BaseModel):
people: List[str] = Field(description="Names of people mentioned")
organizations: List[str] = Field(description="Company/organization names")
locations: List[str] = Field(description="Locations mentioned")
dates: List[str] = Field(description="Dates mentioned")
PROMPT = """
Extract all named entities from the text.
If there are no entities of some type, return an empty list.
"""
result = dataframeit(df.copy(), Entities, PROMPT)
Text Summarization¶
from pydantic import BaseModel, Field
class Summary(BaseModel):
summary: str = Field(description="Summary in up to 50 words")
key_points: list[str] = Field(description="List of 3-5 main points")
main_topic: str = Field(description="Central topic in one word")
PROMPT = """
Analyze the text and extract a concise summary.
Identify the main points and central topic.
"""
result = dataframeit(df.copy(), Summary, PROMPT)
Using Different Input Types¶
With List¶
texts = ['Text 1', 'Text 2', 'Text 3']
result = dataframeit(texts, Sentiment, PROMPT)
# Returns DataFrame with numeric index
With Dictionary¶
documents = {
'doc_001': 'Content of document 1',
'doc_002': 'Content of document 2',
}
result = dataframeit(documents, Sentiment, PROMPT)
# Returns DataFrame with keys as index
With Series¶
series = pd.Series(['Text A', 'Text B'], index=['id_1', 'id_2'])
result = dataframeit(series, Sentiment, PROMPT)
# Preserves original index
Using Different Providers¶
# OpenAI with gpt-6-luna (default)
result = dataframeit(df.copy(), Sentiment, PROMPT)
# Google Gemini
result = dataframeit(
df.copy(), Sentiment, PROMPT,
provider='google_genai',
model='gemini-3.8-flash'
)
# Anthropic Claude
result = dataframeit(
df.copy(), Sentiment, PROMPT,
provider='anthropic',
model='claude-sonnet-5'
)
Next Steps¶
- Structured Output: Advanced Pydantic models
- Error Handling: Retry and fallbacks
- Performance: Parallelism and rate limiting