Fix pandas syntax errors in system prompt
Browse files- Add specific guidance for correct groupby syntax: df.groupby([df['col1'], df['col2'].dt.year])
- Prevent common error: groupby(['col1', 'col2'].dt.year) which causes 'list' object has no attribute 'dt'
- Add guidance for proper DataFrame column references in all operations
- Expand CRITICAL section to cover pandas syntax fixes, not just numpy indexing
- This should fix the recurring pandas attribute access errors
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
src.py
CHANGED
@@ -310,11 +310,14 @@ SAFETY & ROBUSTNESS RULES:
|
|
310 |
- Validate date ranges exist in data
|
311 |
- Use proper string formatting for answers with units (μg/m³)
|
312 |
|
313 |
-
CRITICAL:
|
314 |
- ALWAYS convert pandas/numpy values to int before using as list indices
|
315 |
-
- Example: calendar.month_name[int(month_value)] NOT calendar.month_name[month_value]
|
316 |
- Use int() conversion for ANY value used as index: int(row['month']), int(max_idx), etc.
|
317 |
- When accessing pandas iloc results, wrap in int(): int(df.loc[idx, 'column'])
|
|
|
|
|
|
|
318 |
|
319 |
TECHNICAL REQUIREMENTS:
|
320 |
- Save final result in variable called 'answer'
|
|
|
310 |
- Validate date ranges exist in data
|
311 |
- Use proper string formatting for answers with units (μg/m³)
|
312 |
|
313 |
+
CRITICAL: PANDAS SYNTAX FIXES:
|
314 |
- ALWAYS convert pandas/numpy values to int before using as list indices
|
315 |
+
- Example: calendar.month_name[int(month_value)] NOT calendar.month_name[month_value]
|
316 |
- Use int() conversion for ANY value used as index: int(row['month']), int(max_idx), etc.
|
317 |
- When accessing pandas iloc results, wrap in int(): int(df.loc[idx, 'column'])
|
318 |
+
- CORRECT groupby syntax: df.groupby([df['col1'], df['col2'].dt.year]) NOT df.groupby(['col1', 'col2'].dt.year)
|
319 |
+
- Always reference DataFrame when accessing columns: df['column'].dt.year NOT 'column'].dt.year
|
320 |
+
- Use proper DataFrame column references in all operations
|
321 |
|
322 |
TECHNICAL REQUIREMENTS:
|
323 |
- Save final result in variable called 'answer'
|