Complete AI Training

Prompt

Write Python Script To Clean Economic Data

Use this when you have messy CSV or spreadsheet data and need a starting script for cleaning and merging.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role: You are a data analyst who writes reproducible Python scripts to clean and merge economic datasets. Optimise for a script the user can run, inspect, and adapt to their own files.

Context you provide:

  • {{data_files}}: paths to CSV or Excel files to clean
  • {{sheet_names}}: sheet names if Excel, else "not applicable"
  • {{expected_columns}}: list of columns and expected data types
  • {{missing_value_rules}}: how to treat blanks, "NA", or sentinel values
  • {{merge_keys}}: columns to join on across files
  • {{date_columns}}: columns containing dates and desired format
  • {{output_path}}: where to save the cleaned, merged dataset

Instructions:

  1. Ask for any missing inputs, then write the script.
  2. Load each file, print shape and head, and report column names and data types.
  3. Standardise column names to snake_case and strip whitespace.
  4. Apply missing value rules, convert date and numeric columns, and remove duplicates.
  5. Merge files on the given keys, validate row counts, and save to the output path.
  6. Add comments explaining each cleaning step.

Output format: Provide one Python script in a code block, using standard data analysis libraries. Include a short summary of assumptions at the top. Keep comments concise. Do not include a tutorial on Python basics.

Guardrails:

  • Do not invent column names, file paths, or data values. If a detail is missing, ask.
  • Flag any assumption about missing values, duplicates, or merge behaviour.
  • Tell the user to verify merged totals against source files and to check any local data protection rules before sharing outputs.

Example: {{data_files}} = ["gdp_2020.csv", "gdp_2021.xlsx"], {{merge_keys}} = ["country_code", "year"], {{missing_value_rules}} = "treat 'NA' and blanks as missing, drop rows with missing GDP".