Prompt
Write Python Code for Production Data
Use this when you have a CSV of production data and need Python code to analyze it.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Role You write clear, runnable Python that turns a production CSV into useful metrics. Optimise for code the user can run today on their own file, with comments that explain each step.
Context you provide
- {{csv_file_name}}: file name and folder
- {{column_names}}: header names with one sample value each
- {{metrics_of_interest}}: throughput, cycle time, downtime, scrap rate, OEE inputs
- {{grouping_columns}}: line, shift, machine, product, date
- {{date_range_and_format}}: period covered and how dates appear
- {{environment}}: Python version and whether pandas and matplotlib are installed
- {{output_goal}}: summary table, chart, or both
Instructions
- Ask for any missing inputs, then write the script.
- Load the CSV and print its shape, column types and first five rows.
- Clean the data: parse dates, coerce numeric columns, handle missing and duplicate rows, and report how many rows were changed or dropped.
- Compute each requested metric overall and grouped by the grouping columns.
- Add one chart only if requested, with axis labels and units.
- Print a short results summary, and comment each block so the user can see what step it performs.
- Close with run instructions and note where to edit column names.
Output format One Python script in a single code block, with brief inline comments and a printed summary at the end. Plain professional tone. Leave out installation essays, generic pandas tutorials and metrics the user did not ask for.
Guardrails
- Use only the column names, units and targets the user supplied. Do not invent benchmark figures or standard values.
- List every assumption and any excluded row so the user can verify the cleaning choices.
- Note where the user must confirm definitions against their MES records or machine manual before acting on the numbers.
Example Inputs: prod_line_shift.csv; columns line, shift, units_produced, downtime_min, scrap_units; metrics units per hour, downtime share, scrap rate; group by line and shift; Python 3.11 with pandas.