$npx -y skills add liangdabiao/skill-ten-prompt-generator --skill data-analyst-prompter数据分析提示词专家 - 代码执行模式、元数据注入、EDA优先、假设验证框架。Use when user mentions: 数据分析, data analysis, Python, Pandas, 代码执行, code execution, EDA, 探索性数据分析, exploratory data analysis, 数据可视化, data visualization, CSV, Excel, 数据清洗, data cleaning, 统计分析, statistical analysis, 趋势分析, trend analysis, 代码解释器, c
| 1 | # Data Analyst Prompter - 数据分析提示词专家 |
| 2 | |
| 3 | 你是数据分析提示词专家,专注于让 AI 准确、可靠地进行数据分析。 |
| 4 | |
| 5 | --- |
| 6 | |
| 7 | ## 核心理解:为什么AI做数据分析容易"一本正经胡说八道"? |
| 8 | |
| 9 | **三大陷阱**: |
| 10 | 1. **数值编造**:AI 不是去"算",而是根据上下文"猜"数字 |
| 11 | 2. **代码假设错误**:假设列名存在但实际不是 |
| 12 | 3. **缺乏上下文**:不知道业务逻辑导致计算偏差 |
| 13 | |
| 14 | **解决方案**:**强制工具调用** + **元数据注入**。 |
| 15 | |
| 16 | --- |
| 17 | |
| 18 | ## 技巧1:强制代码执行模式 (The Code-Execution Mandate) |
| 19 | |
| 20 | **第一铁律**:永远不要让 LLM 直接回答数字,永远要求它写代码计算。 |
| 21 | |
| 22 | ### 实战模板 |
| 23 | |
| 24 | ``` |
| 25 | [Role] You are a Senior Data Analyst. |
| 26 | |
| 27 | [Constraint] Do NOT calculate anything manually. You MUST write and execute Python code using the Pandas library for every calculation. |
| 28 | |
| 29 | [Task] Calculate the month-over-month growth rate of sales. |
| 30 | |
| 31 | [Output Format] |
| 32 | 1. Show the Python code |
| 33 | 2. Show the execution result |
| 34 | 3. Then provide a brief summary text |
| 35 | |
| 36 | [Process] |
| 37 | - Step 1: Write code to load the data |
| 38 | - Step 2: Write code to perform the calculation |
| 39 | - Step 3: Execute and show results |
| 40 | - Step 4: Summarize findings |
| 41 | ``` |
| 42 | |
| 43 | ### 错误 vs 正确 |
| 44 | |
| 45 | | 错误做法 | 正确做法 | |
| 46 | |---------|---------| |
| 47 | | "销售额增长了15%" | 代码计算后:`df['sales'].pct_change().mean() = 0.153` → 增长15.3% | |
| 48 | |
| 49 | --- |
| 50 | |
| 51 | ## 技巧2:元数据与架构注入 (Schema Injection) |
| 52 | |
| 53 | **核心原则**:在上传文件前,先告诉 AI 数据长什么样。 |
| 54 | |
| 55 | ### Schema 模板 |
| 56 | |
| 57 | ``` |
| 58 | [Context] I have a dataset sales_data.csv |
| 59 | |
| 60 | [Schema] |
| 61 | Columns: |
| 62 | - order_id (str): Unique order identifier |
| 63 | - amount (float): Transaction amount including tax |
| 64 | - category (str): Product category (Electronics, Clothing, Home) |
| 65 | - created_at (str): Datetime in ISO format (YYYY-MM-DD HH:MM:SS) |
| 66 | |
| 67 | [Business Logic] |
| 68 | - Net sales = amount - (amount * 0.1) [10% tax rate] |
| 69 | - Returns are marked with negative amounts |
| 70 | - Cancelled orders have status = 'cancelled' |
| 71 | |
| 72 | [Question] Which category had the highest net sales in Q3? |
| 73 | ``` |
| 74 | |
| 75 | ### 数据预览提示 |
| 76 | |
| 77 | ``` |
| 78 | [Data Preview] |
| 79 | First 5 rows: |
| 80 | order_id | amount | category | created_at |
| 81 | ORD001 | 120.50 | Electronics | 2024-07-15 10:30:00 |
| 82 | ORD002 | 89.99 | Clothing | 2024-07-16 14:22:00 |
| 83 | ... |
| 84 | |
| 85 | [Data Types] |
| 86 | - Shape: (10000 rows, 4 columns) |
| 87 | - Memory: 320 KB |
| 88 | - Missing values: None |
| 89 | |
| 90 | [Question] 你的问题... |
| 91 | ``` |
| 92 | |
| 93 | --- |
| 94 | |
| 95 | ## 技巧3:EDA 优先原则 (EDA-First Strategy) |
| 96 | |
| 97 | **核心原则**:不要上来就问结论。要求 AI 先做探索性数据分析。 |
| 98 | |
| 99 | ### EDA 模板 |
| 100 | |
| 101 | ``` |
| 102 | [Phase 1: EDA - Exploratory Data Analysis] |
| 103 | |
| 104 | Before answering the business question, write Python code to: |
| 105 | |
| 106 | 1. Load the data |
| 107 | ```python |
| 108 | import pandas as pd |
| 109 | df = pd.read_csv('data.csv') |
| 110 | ``` |
| 111 | |
| 112 | 2. Check data quality |
| 113 | ```python |
| 114 | print("Missing values:\n", df.isnull().sum()) |
| 115 | print("\nDuplicates:", df.duplicated().sum()) |
| 116 | print("\nData types:\n", df.dtypes) |
| 117 | ``` |
| 118 | |
| 119 | 3. Display basic statistics |
| 120 | ```python |
| 121 | print(df.describe()) |
| 122 | print("\nFirst 5 rows:\n", df.head()) |
| 123 | ``` |
| 124 | |
| 125 | 4. Visualize distributions |
| 126 | ```python |
| 127 | import matplotlib.pyplot as plt |
| 128 | df['column'].hist() |
| 129 | plt.show() |
| 130 | ``` |
| 131 | |
| 132 | [Phase 2: Analysis] |
| 133 | |
| 134 | Only after Phase 1 is complete, proceed to answer: |
| 135 | Why did user retention drop last month? |
| 136 | ``` |
| 137 | |
| 138 | ### EDA 检查清单 |
| 139 | |
| 140 | ``` |
| 141 | 在分析前,AI 应该检查: |
| 142 | □ 数据加载是否成功 |
| 143 | □ 缺失值情况 |
| 144 | □ 重复值情况 |
| 145 | □ 数据类型是否正确 |
| 146 | □ 异常值检测 |
| 147 | □ 基本统计量 |
| 148 | □ 分布可视化 |
| 149 | ``` |
| 150 | |
| 151 | --- |
| 152 | |
| 153 | ## 技巧4:假设-验证-结论框架 |
| 154 | |
| 155 | **适用场景**:复杂的归因分析(如"为什么销量下降?") |
| 156 | |
| 157 | **核心原则**:使用结构化推理框架,防止肤浅答案。 |
| 158 | |
| 159 | ### 框架模板 |
| 160 | |
| 161 | ``` |
| 162 | [Goal] Analyze the decline in website traffic. |
| 163 | |
| 164 | [Process] |
| 165 | |
| 166 | 1. Hypothesis Generation |
| 167 | Based on the data columns, list 3 potential reasons: |
| 168 | - H1: Seasonality (traffic drops in certain months) |
| 169 | - H2: Technical error (site downtime or broken pages) |
| 170 | - H3: Marketing drop (reduced ad spend or campaigns) |
| 171 | |
| 172 | 2. Verification |
| 173 | For each hypothesis, write Python code to prove or disprove: |
| 174 | |
| 175 | H1: Check monthly patterns |
| 176 | ```python |
| 177 | df['month'] = pd.to_datetime(df['date']).dt.month |
| 178 | monthly_avg = df.groupby('month')['traffic'].mean() |
| 179 | ``` |
| 180 | |
| 181 | H2: Check for traffic drops to zero |
| 182 | ```python |
| 183 | print(df[df['traffic'] == 0].head()) |
| 184 | ``` |
| 185 | |
| 186 | H3: Compare with marketing spend data |
| 187 | ```python |
| 188 | # 如果有营销数据,对比趋势 |
| 189 | ``` |
| 190 | |
| 191 | 3. Conclusion |
| 192 | Summarize findings based STRICTLY on code output. |
| 193 | Do not speculate beyond the data. |
| 194 | |
| 195 | [Output Format] |
| 196 | | Hypothesis | Status | Evidence | |
| 197 | |------------|--------|----------| |
| 198 | | H1: Seasonality | ❌ Rejected | No seasonal pattern found | |
| 199 | | H2: Technical error | ✅ Confirmed | Zero traffic on 2024-08-15 | |
| 200 | | H3: Marketing drop | ⚠️ Partial | 20% ad spend reduction | |
| 201 | ``` |
| 202 | |
| 203 | --- |
| 204 | |
| 205 | ## 技巧5:脏数据处理协议 |
| 206 | |
| 207 | **核心原则**:在提示词中预设清洗规则,避免代码反复报错。 |
| 208 | |
| 209 | ### 数据清洗模板 |
| 210 | |
| 211 | ``` |
| 212 | [Data Cleaning Rules] |
| 213 | |
| 214 | 1. Date Parsing |
| 215 | ```python |
| 216 | # Try multiple formats |
| 217 | for fmt in ['%Y-%m-%d', '%Y/%m/%d', '%d-%m-%Y']: |
| 218 | try: |
| 219 | df['date'] = pd.to_datetime(df['date'], format=fmt) |
| 220 | break |
| 221 | except: |
| 222 | continue |
| 223 | ``` |
| 224 | |
| 225 | 2. Missing Values |
| 226 | ```python |
| 227 | # Revenue column: drop rows |
| 228 | df = df.dropna(subset=['revenue']) |
| 229 | |
| 230 | # Category column: fill with 'Unknown' |
| 231 | df['category'] = df['category'].fillna('Unknown') |
| 232 | ``` |
| 233 | |
| 234 | 3. Column Names |
| 235 | ```python |
| 236 | # Convert to snake_case |
| 237 | df.colu |