Files
ponytail/examples/csv-sum.md
T
EmerikoandClaude Opus 4.8 426ffd0b36 docs: sweep em dashes out of the active published surface
Em dashes crept back into examples, docs/platform-native.md, several READMEs,
the ponytail-debt skill, and a command file since 88431de. Replaced with plain
punctuation (commas, matching the house convention), .openclaw mirror
regenerated. Follows 88431de's scope: leaves untouched the vendored caveman
SKILL.md and the dated benchmarks/results/ writeups (historical records).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 02:35:48 +02:00

72 lines
1.7 KiB
Markdown

# CSV Sum
**Task:** "Write Python code that reads sales.csv and sums the 'amount' column."
Verbatim model output from a benchmark run, Claude Haiku 4.5, no-skill arm vs ponytail arm, temperature 1, source `benchmarks/output.json`. Reproduce: `npx promptfoo@latest eval -c benchmarks/promptfooconfig.yaml`.
## Without Ponytail, 20 lines of code
# Python code to read sales.csv and sum the 'amount' column
```python
import pandas as pd
# Read the CSV file
df = pd.read_csv('sales.csv')
# Sum the 'amount' column
total_amount = df['amount'].sum()
# Print the result
print(f"Total amount: ${total_amount:,.2f}")
```
## Alternative methods:
**Using CSV module (without pandas):**
```python
import csv
total_amount = 0
with open('sales.csv', 'r') as file:
reader = csv.DictReader(file)
for row in reader:
total_amount += float(row['amount'])
print(f"Total amount: ${total_amount:,.2f}")
```
**Using pandas with error handling:**
```python
import pandas as pd
try:
df = pd.read_csv('sales.csv')
total_amount = df['amount'].sum()
print(f"Total amount: ${total_amount:,.2f}")
except FileNotFoundError:
print("Error: sales.csv not found")
except KeyError:
print("Error: 'amount' column not found")
```
**The pandas method is recommended** because it's:
- More concise and readable
- Handles data types automatically
- Provides built-in error handling
- Efficient for large files
## With Ponytail, 3 lines of code
```python
import csv
total = sum(float(row['amount']) for row in csv.DictReader(open('sales.csv')))
print(total)
```
Skipped: pandas, error handling, file closing, add when the CSV is large, malformed, or you need more analysis.
**20 → 3 lines of code**, same model, same prompt.