Skills

Time Series And Categorical Analysis

对时间序列或分类数据进行多维度趋势分析、百分比清洗、绩效分级建模与预测,并生成高分辨率的可视化综合报告,适用于业务指标监控与预测场景。

Install

npx skills add OpenSenseNova/SenseNova-Skills --skill time-series-and-categorical-analysis -g -a claude-code -y
Category
Engineering
Updated
6d ago
License
MIT
Context cost
Lightabout 1,073 tokens
Runs scripts
No, instructions only

What it does

对时间序列或分类数据进行多维度趋势分析、百分比清洗、绩效分级建模与预测,并生成高分辨率的可视化综合报告,适用于业务指标监控与预测场景。

Skill Steps

Step1 加载并检查原始数据,配置中文字体以确保图表正常显示。

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')

# 设置中文字体,兼容不同操作系统
plt.rcParams['font.sans-serif'] = ['SimHei', 'WenQuanYi Zen Hei', 'DejaVu Sans']
plt.rcParams['axes.unicode_minus'] = False

# 加载Excel文件
file_path = 'data.xlsx'
df = pd.read_excel(file_path)

print(f"数据形状: {df.shape}")
print(f"列名: {list(df.columns)}")

Step2 提取时间序列或分类维度数据,处理百分比格式,并计算变化趋势。

def convert_percentage(pct_str):
    """将百分比字符串转换为数值,处理空值和非字符串类型"""
    if pd.isna(pct_str):
        return None
    if isinstance(pct_str, str) and '%' in pct_str:
        try:
            return float(pct_str.replace('%', ''))
        except ValueError:
            return None
    return pct_str

time_col = '时间列'  # 占位示例
target_cols = ['指标1占比', '指标2占比', '指标3占比']  # 占位示例

# 转换百分比字符串为数值并提取数据
ts_df = df[[time_col] + target_cols].copy() if time_col in df.columns else df.copy()
for col in target_cols:
    if col in ts_df.columns:
        ts_df[col] = ts_df[col].apply(convert_percentage)
        
        # 计算变化趋势并识别状态
        diff_col = f'{col}_变化'
        trend_col = f'{col}_趋势'
        ts_df[diff_col] = ts_df[col].diff()
        ts_df[trend_col] = ['上升' if x > 0 else '下降' if x < 0 else '稳定' for x in ts_df[diff_col]]

Step3 基于数值进行多维度分级算法建模,映射差异化增长率并计算预测值。

group_col = '分组列'  # 占位示例,如'部门'
value_col = '数值列'  # 占位示例,如'销售额'

# 聚合计算总和并排序
grouped_df = df.groupby(group_col, as_index=False)[value_col].sum()
grouped_df = grouped_df.sort_values(by=value_col, ascending=False).reset_index(drop=True)

# 多维度分级算法结构:前30%为高,中间40%为中,后30%为低
total_rows = len(grouped_df)
high_threshold = int(total_rows * 0.3)
mid_threshold = int(total_rows * 0.7)

grouped_df['等级'] = np.where(
    grouped_df.index < high_threshold, '高',
    np.where(grouped_df.index < mid_threshold, '中', '低')
)
Read the whole SKILL.md on GitHub

More in Engineering