关于 data-science
data-science 是用于 SQL 查询、数据探索、可视化、统计分析和 ETL 工作的技能,为使用 SQL 和 Python 处理数据集的分析人员提供模式示例。
主要功能
- 01编写 SQL 查询并使用窗口函数
- 02使用 pandas 和 NumPy 探索数据
- 03执行统计检验和相关性分析
- 04处理 BigQuery 分区与数组
- 05组织分析摘要和发现
适用场景
- 01按队列分析用户留存
- 02使用 RFM 分析对客户排序
- 03探索 CSV 文件中的数据
- 04检验不同群体之间的差异
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ htlin222/ dotfiles --skill data-science安装后在 Claude Code 中输入/data-science确认已加载。
详细介绍
数据科学
数据分析、SQL 和洞察生成。
适用场景
- 编写 SQL 查询
- 数据分析与探索
- 创建可视化图表
- 统计分析
- ETL 和数据管道
SQL 模式
常见查询
-- Aggregation with window functions
SELECT
user_id,
order_date,
amount,
SUM(amount) OVER (PARTITION BY user_id ORDER BY order_date) as running_total,
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY order_date DESC) as recency_rank
FROM orders;
-- CTEs for readability
WITH monthly_stats AS (
SELECT
DATE_TRUNC('month', created_at) as month,
COUNT(*) as total_orders,
SUM(amount) as revenue
FROM orders
GROUP BY 1
),
growth AS (
SELECT
month,
revenue,
LAG(revenue) OVER (ORDER BY month) as prev_revenue,
(revenue - LAG(revenue) OVER (ORDER BY month)) / NULLIF(LAG(revenue) OVER (ORDER BY month), 0) as growth_rate
FROM monthly_stats
)
SELECT * FROM growth;
BigQuery 特定内容
-- Partitioned table query
SELECT *
FROM `project.dataset.events`
WHERE DATE(_PARTITIONTIME) BETWEEN '2024-01-01' AND '2024-01-31';
-- UNNEST for arrays
SELECT
user_id,
item
FROM `project.dataset.orders`,
UNNEST(items) as item;
-- Approximate counts for large data
SELECT APPROX_COUNT_DISTINCT(user_id) as unique_users
FROM `project.dataset.events`;
Python 分析
import pandas as pd
import numpy as np
# Load and explore
df = pd.read_csv('data.csv')
df.info()
df.describe()
# Clean and transform
df['date'] = pd.to_datetime(df['date'])
df = df.dropna(subset=['required_field'])
df['category'] = df['category'].fillna('Unknown')
# Aggregate
summary = df.groupby('category').agg({
'value': ['mean', 'sum', 'count'],
'date': ['min', 'max']
}).round(2)
# Visualize
import matplotlib.pyplot as plt
df.groupby('date')['value'].sum().plot(figsize=(12, 6))
plt.title('Daily Values')
plt.savefig('chart.png', dpi=150, bbox_inches='tight')
统计分析
from scipy import stats
# Hypothesis testing
t_stat, p_value = stats.ttest_ind(group_a, group_b)
# Correlation
correlation = df['x'].corr(df['y'])
# Regression
from sklearn.linear_model import LinearRegression
model = LinearRegression().fit(X, y)
print(f"R² = {model.score(X, y):.3f}")
输出格式
## Analysis Summary
**Question:** [What we're trying to answer]
**Data Source:** [Tables/files used]
**Date Range:** [Time period]
### Key Findings
1. [Finding with supporting metric]
2. [Finding with supporting metric]
### Visualization
[Chart description or embedded image]
### Recommendations
- [Actionable insight]
示例
输入:“分析用户留存率” **操作:**查询队列数据,计算留存率,并将趋势可视化
输入:“找出顶级客户” **操作:**编写用于 RFM 分析的 SQL,对用户进行分群,并总结发现
评论
支持 Markdown