Workflows Intermediate Claude Code 8 min read ·

Automate Your Data Work: AI Coding for Analysts

Use AI to write Python scripts that clean data, build charts, connect to APIs, and schedule automated reports. No prior coding needed.

If you spend hours cleaning spreadsheets, building the same reports each week, or manually pulling data from different sources, AI coding tools can automate most of that work. You don't need to become a programmer — you need to describe your repetitive tasks clearly, and the AI will write the Python scripts to handle them.

Getting Set Up

Install Python from python.org and set up Claude Code (or use Cursor if you prefer). For data work, you'll use three Python libraries constantly: pandas for data manipulation, matplotlib or plotly for charts, and requests for API connections. The AI will install these for you when needed — just mention them in your prompt or let the AI suggest them.

Cleaning CSV Data Automatically

Every analyst has that messy CSV that needs the same cleanup every time. Here's how to automate it:

plaintext
Write a Python script that cleans my sales data CSV. The file is 'monthly_sales.csv' with columns: Date, Product, Region, Revenue, Units Sold.

The script should:
1. Remove rows where Revenue is blank or zero
2. Standardize the Date column to YYYY-MM-DD format (current data mixes MM/DD/YYYY and DD-MM-YYYY)
3. Trim whitespace from all text columns
4. Remove duplicate rows
5. Sort by Date ascending
6. Save the cleaned data to 'monthly_sales_cleaned.csv'
7. Print a summary: how many rows before vs after, how many duplicates removed

Run this script once, and it handles in seconds what used to take 30 minutes of manual spreadsheet work. Save the script and reuse it every month when new data arrives.

Building Charts and Reports

Stop rebuilding the same charts in Excel every week. Create them programmatically:

plaintext
Using the cleaned sales CSV, create a Python script that generates a PDF report with:
1. A bar chart showing total revenue by region
2. A line chart showing monthly revenue trend over time
3. A table of the top 10 products by units sold
4. Summary statistics at the top: total revenue, average order value, total units

Use matplotlib for charts. Make the charts look professional with a clean style, proper labels, and a consistent color palette. Save the report as 'sales_report.pdf'.

Connecting to APIs

Many data sources offer APIs that let you pull data automatically instead of downloading CSVs by hand.

plaintext
Write a Python script that pulls data from [API name] and saves it to a CSV. Here's the API documentation URL: [URL]. I have an API key: [store it securely, not hardcoded]. The script should:
1. Fetch all records from the /reports endpoint for the current month
2. Parse the JSON response into a flat table
3. Save to a CSV with clear column headers
4. Handle errors gracefully (API timeout, rate limits, invalid responses)
5. Log what happened to a log file
Pro Tip

Never paste API keys directly into prompts or code. Ask the AI to read the key from an environment variable or a .env file. This keeps your credentials safe and makes the script shareable without exposing secrets.

Scheduling Automated Reports

Once your scripts work manually, schedule them to run automatically:

plaintext
Create a Python script that:
1. Runs my data cleaning script (clean_sales.py)
2. Then runs my report generation script (generate_report.py)
3. Emails the generated PDF report to [email address] with the subject 'Weekly Sales Report - [date]'
4. Logs the entire process to a file with timestamps
5. If any step fails, send an error notification email instead

Also show me how to schedule this to run every Monday at 8 AM using cron (Mac/Linux) or Task Scheduler (Windows).

Building a Simple Dashboard

For data you check frequently, a live dashboard beats static reports:

plaintext
Create a simple web dashboard using Python and Streamlit that:
1. Loads data from my cleaned CSV
2. Shows key metrics at the top (total revenue, units, average order value)
3. Has dropdown filters for Region and Product
4. Displays an interactive line chart of revenue over time
5. Shows a data table that updates based on the filters

Keep it simple — no authentication needed, this is for internal use only.

Streamlit turns a Python script into a web dashboard with minimal code. The AI handles the setup. You just describe what data to show and how to filter it. Run it locally or deploy it to Streamlit Cloud for free to share with your team.

What to Automate Next

Look at your weekly tasks and identify anything repetitive: downloading data, formatting reports, combining spreadsheets, checking for anomalies, sending summaries. Each of these can become a script that runs in minutes instead of hours. Start with the task you do most often and work outward from there.

Key Takeaway

Describe your repetitive data tasks to an AI coding tool, and it writes Python scripts that automate the work. Start with CSV cleaning and report generation, then add API connections and scheduling as you get comfortable.

Frequently Asked Questions

Do I need to learn Python before using AI to write data scripts?

No. The AI writes the Python code for you. However, understanding basic Python concepts (variables, loops, functions) helps you describe problems more precisely and debug issues faster. Many analysts pick up the basics naturally after a few AI-assisted projects.

Can AI-generated scripts handle large datasets?

For most analyst workflows — files under a few hundred thousand rows — AI-generated pandas scripts work well. For millions of rows, you may need the AI to write code using chunked processing or a database. Tell the AI your file size and it will choose the right approach.

← Back to AI Coding Hub