AI Prompt to Write a Python Script
Most people ask AI to “Write a Python script to process my CSV”—and wonder why the output is mediocre. Here's how to write a prompt that actually gets you what you want on the first try.
Last updated · By the Prompt Orange team
“Write a Python script to process my CSV”
Too vague—AI has to guess what you want
“Write a Python 3.11 script to process a CSV file with columns: date, product_name, revenue, units_sold. The script should: load the file with pandas, clean nulls and data type errors, calculate total revenue and average units per product, output a summary CSV and print a brief report to the terminal. Add docstrings and inline comments. Handle FileNotFoundError gracefully.”
Specific, clear, ready to use
What makes the strong prompt better?
Python version specified prevents outdated syntax
Column names provided means the script is immediately runnable after minor edits
Error handling instruction prevents a script that crashes on basic edge cases