Numbers Are Cold, What the Boss Wants to Hear Is a "Story"

Through previous chapters, we've learned to automatically scrape competitors' prices, calculate averages with Pandas, create beautiful bar charts, and even have Python email reports directly to the boss.

This sounds perfect, right? But you're missing the final piece of the puzzle.

When your boss opens your email in the morning and sees that bar chart, they might think: "The chart looks great, but what does it mean? Did our competitors lower their prices? Is our current pricing strategy competitive? What decisions should I make next?"

If you only provide charts and numbers, you're just a "high-level operator." If you can deliver charts along with three sharp "Business Insights", you become an irreplaceable "data strategy consultant."

Previously, writing insight reports required exceptional business acumen and extensive experience. But now, we're outsourcing this most mentally demanding task to the world's smartest brain: OpenAI (Large Language Model LLM).


🧠 Upgrading the Data Analysis Workflow: Pandas + LLM Collaboration

We're taking the Chapter 5 workflow to the next level: Web Scraping ➡️ Pandas Analysis ➡️ 【Convert Pandas Data to JSON for OpenAI】 ➡️ 【OpenAI Generates Business Report】 ➡️ Email to Boss.

Vibe Prompt in Action: Helping AI Understand Your Data

To call OpenAI in Python, first install the package in terminal: pip install openai. Then, we give Cursor this instruction to connect Pandas results with LLM:

【AI Business Insights Report Generation Prompt】 I'm conducting data analysis in Python. I've already calculated two key metrics with Pandas:

  1. my_avg_price: Our product's average price (e.g., 500)
  2. competitor_avg_price: Competitors' average price (e.g., 450)
  3. market_trend: Recent weekly market search trend string (e.g., "three consecutive days of decline")

Please write a function generate_ai_insight(my_price, comp_price, trend). Requirements:

  1. Use the openai package to call the gpt-4o-mini model.
  2. Write a strict System Prompt: "You are a top-tier business data consultant earning $300K annually. Your task is to write a concise and impactful 'Daily Market Insights Report' in Traditional Chinese based on provided data. The report must include 'Current Situation Analysis' and 'Specific Pricing or Marketing Recommendations.' Limit to 150 words, maintaining a professional and sharp tone."
  3. Combine the three variables into a User message for AI.
  4. Return the AI-generated text report as a string.

The Magical Code Generated by AI:

import openai
import os

# Remember to store the key in .env - this is just a demo
openai.api_key = "sk-your-openai-api-key"

def generate_ai_insight(my_price, comp_price, trend):
    print("🧠 Consulting AI analyst for insights...")
    
    prompt = f"""
    Today's data:
    - Our product's average price: {my_price} NTD
    - Competitors' average price: {comp_price} NTD
    - Recent market trend: {trend}
    """
    
    try:
        response = openai.chat.completions.create(
            model="gpt-4o-mini",
            messages=[
                {"role": "system", "content": "You are a top-tier business data consultant earning $300K annually. Your task is to write a concise and impactful 'Daily Market Insights Report' in Traditional Chinese based on provided data. The report must include 'Current Situation Analysis' and 'Specific Pricing or Marketing Recommendations.' Limit to 150 words, maintaining a professional and sharp tone."},
                {"role": "user", "content": prompt}
            ],
            temperature=0.7 # Slightly creative analytical style
        )
        
        insight_text = response.choices[0].message.content
        return insight_text
        
    except Exception as e:
        return f"🚨 AI analysis failed: {e}"

# Test run
insight = generate_ai_insight(500, 450, "three consecutive days of decline")
print("==============================")
print(insight)
print("==============================")

Let's See What the AI Consultant Wrote:

Execution Result:

📊 【Daily Market Insights Report】 Current Situation: Our product's average price (500 NTD) is approximately 11% higher than competitors' (450 NTD), while market search volume shows a "three consecutive days of decline" warning sign. This indicates consumer migration to lower-priced alternatives. Recommendations: Avoid blind price cuts that may devalue the brand. Recommend immediately launching "flash spend-and-get" or "buy A get B free" promotions to effectively reduce purchase cost to ~460 NTD range, coupled with social media limited-time offers to create urgency.


👑 Mastering the Peak of Value

Do you see it now? If you only deliver the numbers "500 and 450," your value is 0 (because even a calculator can do that). But when you include that AI-generated insight report in your email along with the chart, you become an invaluable talent in your boss's eyes.

This is the ultimate essence of Vibe Coding. We write code not to prove we understand loops or functions. We write code to "automate tedious labor," then dedicate all saved mental energy and time to "creating higher business value."

Congratulations! The "Python Data Analysis & Automation" course is now complete. Take your web scraping, Pandas, visualization, and AI analysis skills—and go build your own money-printing machine!

Unlock Full Tutorial

This chapter is paid content. Join the project to unlock over 5000 words of deep analysis, including 10+ god-tier Prompts and real Source Code examples!