Claude Code Như Junior Data Analyst: Từ Zero Đến Báo Cáo Đầu Tiên — Workflow Thực Tế
Điểm nổi bật
Nhấn để đến mục tương ứng
- 1 Mặt trái đáng cân nhắc kỹ trước khi đầu tư: Complex statistical models cần expertise và verification Data privacy: Cẩn thận với sensitive data — đặc b. Đây không phải lý do từ chối nhưng là yếu tố quyết định bạn nên bắt đầu từ đâu và kỳ vọng thế nào.
- 2 Setup đơn giản hơn bạn tưởng: Step 1: SQL Query Generation Claude đọc onboarding doc → understand schema → generate SQL queries chính xác. Với documentation tốt, queries thường đúng ngay lần đầu. Bắt đầu với cấu hình tối thiểu, chạy thử ngay rồi tinh chỉnh dần — đừng cố hoàn hảo từ bước đầu tiên.
- 3 Ứng dụng sáng tạo vượt xa mục đích ban đầu: Core của approach này là một file text đơn giản: todo.txt . Claude không execute tất cả cùng lúc — nó loop qua từng task, complete xong rồi move đến task tiếp. Những use case này minh chứng rằng tiềm năng thực sự chỉ được mở ra khi người dùng dám thử nghiệm.
- 4 Điểm then chốt đáng ghi nhớ: Insight #61 trong nghiên cứu Claude.vn ghi nhận đây là use case "todo.txt driven workflow" — một pattern đơn giản nhưng hiệu quả. Kết quả: với setup đúng, yes. Đây là kiến thức nền tảng giúp bạn đưa ra quyết định đúng đắn khi đánh giá và chọn giải pháp.
- 5 Quan sát then chốt: Đây là phần quan trọng nhất và thường bị bỏ qua trong hướng dẫn thông thường. Hiểu chi tiết này cho phép khai thác tối đa tiềm năng của công cụ thay vì chỉ chạm bề mặt tính năng.
Ý Tưởng: Junior Analyst Không Bao Giờ Nghỉ Phép
Bài viết từ Towards AI đặt ra một question thực dụng: Bạn có thể chạy Claude Code như một junior data analyst không — người sẽ lấy data, chạy queries, tạo charts, và output report hoàn chỉnh mà không cần supervision liên tục?
Insight #61 trong nghiên cứu Claude.vn ghi nhận đây là use case "todo.txt driven workflow" — một pattern đơn giản nhưng hiệu quả đáng ngạc nhiên.
Kết quả: với setup đúng, yes — nhưng lần đầu thử thường fail. Bài học thú vị nhất không phải là workflow thành công mà là tại sao nó fail ở lần đầu.
Kiến Trúc: Todo.txt Driven Workflow
Core của approach này là một file text đơn giản: todo.txt. Claude không execute tất cả cùng lúc — nó loop qua từng task, complete xong rồi move đến task tiếp theo, tự update status.
Ví dụ todo.txt:
[ ] Connect to database
[ ] Query total revenue by month Q1 2026
[ ] Query top 10 products by revenue
[ ] Query customer retention rate
[ ] Generate bar chart: monthly revenue
[ ] Generate pie chart: product breakdown
[ ] Write analysis section: key findings
[ ] Compile final report to report.docx
Master prompt để kick off workflow:
You are a junior data analyst.
Read todo.txt and complete each task sequentially.
After completing each task, update its status to [x].
Output all charts as PNG files.
Compile everything into final_report.docx.
Do not skip tasks. Report any errors immediately.
Claude sau đó execute như một script — SQL queries → charts → analysis → report — với todo.txt như checklist.
Lần Đầu: Thất Bại Liên Tục
Đây là phần quan trọng nhất và thường bị bỏ qua trong hướng dẫn thông thường.
Khi Towards AI team chạy workflow lần đầu mà không có documentation về database, kết quả là:
- Claude guess sai tên tables: tìm "customers" nhưng table thực tế là "client_master"
- Guess sai column names: tìm "revenue" nhưng column là "total_amount_net"
- Guess sai data types và relationships giữa tables
- Queries fail hàng loạt → workflow stuck
"Lần 1 errors liên tục. Claude không biết database schema — và không có documentation, nó phải guess. Và guess sai."
Điều này nghe có vẻ hiển nhiên sau khi nghe — nhưng nhiều người bỏ qua bước này và sau đó blame AI khi nó "không hoạt động."
Onboarding Doc: Chìa Khóa Của Success
Giải pháp: tạo một onboarding document cho Claude — giống như bạn sẽ onboard một junior analyst thực sự.
File database_onboarding.md nên bao gồm:
1. Database Overview
# Database Overview
## System: PostgreSQL 14
## Purpose: E-commerce operations data
## Key Tables
| Table Name | Description | Row Count (approx) |
|-----------|-------------|-------------------|
| orders | All customer orders | ~500,000 |
| order_items | Line items per order | ~2M |
| products | Product catalog | ~10,000 |
| customers | Customer profiles | ~150,000 |
2. Schema Details
## orders table
- id: integer (primary key)
- customer_id: integer (FK → customers.id)
- created_at: timestamp
- total_amount_net: decimal (after discounts, excluding tax)
- status: varchar ('pending', 'completed', 'cancelled', 'refunded')
3. Common Queries và Gotchas
## Important Notes
- "Revenue" = total_amount_net where status = 'completed'
- Always filter out cancelled/refunded orders
- Date format: YYYY-MM-DD
- Timezone: all timestamps are UTC+7 (Vietnam time)
- Never select * from large tables — use LIMIT for exploration
4. Business Logic
## Business Rules
- Q1 2026 = January 1 to March 31, 2026
- "Active customer" = placed ≥1 order in last 90 days
- Retention rate = (returning customers / total customers) × 100
Lần Hai: Thành Công
Với onboarding doc, lần thứ hai hoàn toàn khác:
"It did well! The AI was able to produce correct SQL queries, generate charts, and compile the full report with minimal errors."
Kết quả cụ thể:
- Tất cả SQL queries chạy đúng lần đầu
- Charts được generate với labels và formatting phù hợp
- Analysis text có relevant insights
- Final .docx report ready để present
Tổng thời gian từ kick-off đến hoàn thành: khoảng 15-20 phút (tùy dataset size).
Breakdown Chi Tiết: Claude Làm Gì Ở Mỗi Bước
Step 1: SQL Query Generation
Claude đọc onboarding doc → understand schema → generate SQL queries chính xác. Với documentation tốt, queries thường đúng ngay lần đầu.
Ví dụ query được generate:
-- Monthly revenue Q1 2026
SELECT
DATE_TRUNC('month', created_at) AS month,
SUM(total_amount_net) AS revenue,
COUNT(DISTINCT id) AS order_count,
COUNT(DISTINCT customer_id) AS unique_customers
FROM orders
WHERE
status = 'completed'
AND created_at BETWEEN '2026-01-01' AND '2026-03-31'
GROUP BY 1
ORDER BY 1;
Step 2: Chart Generation
Sau khi có data, Claude dùng Python (matplotlib/seaborn/plotly) để generate charts. Với onboarding doc specify format preferences, output charts có:
- Title và axis labels tiếng Việt hoặc tiếng Anh theo yêu cầu
- Color scheme theo brand guidelines
- Proper formatting cho numbers (VND format, v.v.)
Step 3: Analysis Writing
Claude interpret findings và write analysis. Đây là bước cần review cẩn thận nhất — AI có thể identify patterns đúng nhưng đưa ra causal claims không warranted.
Best practice: yêu cầu Claude viết "Observations" thay vì "Conclusions" — điều này tránh overreaching.
Step 4: Report Compilation
Dùng python-docx hoặc reportlab để compile tất cả thành .docx hay .pdf. Claude generate code tự động nếu được yêu cầu.
Patterns Quan Trọng Từ Bài Học Thực Tế
Pattern 1: "Onboarding First" Là Rule Không Thể Bỏ Qua
Không quan trọng database của bạn lớn hay nhỏ, đơn giản hay phức tạp — luôn tạo onboarding doc trước. Đây là investment một lần, dùng được mãi mãi.
Pattern 2: Todo.txt = Explicit State Machine
Tại sao todo.txt hiệu quả: nó tạo ra explicit state — Claude biết đang ở đâu, đã làm gì, còn làm gì. Không có state → Claude có thể repeat tasks hoặc bỏ skip.
Pattern 3: Verify Before Compile
Không để Claude compile report trước khi bạn verify: (a) Data correctness với một vài spot checks; (b) Chart labels và units đúng; (c) SQL logic match business definitions.
Pattern 4: Iterative Refinement
Không expect perfect output lần đầu. Workflow này best work với 2-3 iterations: lần 1 draft, lần 2 refine, lần 3 final polish.
Scale Up: Automated Weekly Reports
Bước tiếp theo mà Towards AI gợi ý: automate workflow này để chạy hàng tuần mà không cần trigger thủ công.
Với cron job hoặc task scheduler:
# Chạy vào 8:00 sáng mỗi thứ Hai
0 8 * * 1 claude-code run /path/to/weekly-report-workflow.md
Mỗi thứ Hai, Claude tự:
- Pull data tuần vừa qua
- Generate report
- Email báo cáo cho stakeholders
Không cần analyst làm manual work. Analyst có thể tập trung vào deeper analysis và strategic insights.
Limitations Thực Tế
- Complex business logic: Nếu "revenue" phụ thuộc vào nhiều tables và business rules phức tạp, AI cần documentation chi tiết hơn — không phải vài dòng
- Real-time data: Claude Code access data tại thời điểm chạy — không phải real-time streaming
- Statistical analysis: Basic stats (mean, trend) tốt. Complex statistical models cần expertise và verification
- Data privacy: Cẩn thận với sensitive data — đặc biệt nếu dùng Claude API (data đi qua cloud)
Tìm hiểu thêm về Claude Code cho data work tại Claude Code cho Data Analysis.
Hoặc khám phá cách dùng Claude tạo dashboard với Artifacts trong bài Claude Artifacts: Dashboard và Data Visualization.
Nguồn tham khảo
- Towards AI Staff, "Claude Code as a Data Analyst: From Zero to First Report," pub.towardsai.net. Đọc bài gốc
- Anthropic, Claude Code Data Analysis Guide, 2026. Tài liệu chính thức
- Python-docx Documentation. python-docx
Bai viet co huu ich khong?
Bản quyền thuộc về tác giả. Vui lòng dẫn nguồn khi chia sẻ.





