mcpField
B
budget-analyzer

budget-analyzer

github.com/dkyazzentwatwa数据与数据库124116 次安装29 周前更新
代码仓库

关于 budget-analyzer

Budget Analyzer 根据交易数据分析个人或企业支出。它可分类消费、比较不同时段和预算,并生成图表、建议及 PDF 或 HTML 报告。

主要功能

  1. 01按商户或描述自动分类
  2. 02分析月度趋势与期间差异
  3. 03按类别汇总支出
  4. 04预算与实际支出对比
  5. 05生成建议及 PDF、HTML 报告

适用场景

  1. 01检查个人每月消费趋势
  2. 02跟踪企业费用与预算目标
  3. 03比较不同时段的类别支出

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/dkyazzentwatwa/chatgpt-skills --skill budget-analyzer

安装后在 Claude Code 中输入/budget-analyzer确认已加载。

附带文件scripts/budget_analyzer.pyscripts/requirements.txt

详细介绍

预算分析器

用于个人财务和企业预算的综合支出分析工具。

功能

  • 自动分类:按商户/描述对支出进行分类
  • 趋势分析:分析逐月支出模式
  • 周期比较:比较不同时间段的支出
  • 类别细分:按类别生成饼图和柱状图
  • 储蓄建议:找出可削减支出的领域
  • 预算与实际对比:根据预算目标跟踪支出
  • 导出报告:导出 PDF 和 HTML 摘要

快速开始

from budget_analyzer import BudgetAnalyzer

analyzer = BudgetAnalyzer()

# Load transaction data
analyzer.load_csv("transactions.csv",
                  date_col="date",
                  amount_col="amount",
                  description_col="description")

# Analyze spending
summary = analyzer.analyze()
print(summary)

# Get category breakdown
categories = analyzer.by_category()
print(categories)

# Generate report
analyzer.generate_report("budget_report.pdf")

CLI 用法

# Basic analysis
python budget_analyzer.py --input transactions.csv --date date --amount amount

# With custom categories
python budget_analyzer.py --input data.csv --categories custom_categories.json

# Compare two periods
python budget_analyzer.py --input data.csv --compare "2024-01" "2024-02"

# Generate PDF report
python budget_analyzer.py --input data.csv --report report.pdf

# Set budget targets
python budget_analyzer.py --input data.csv --budget budget.json --report report.pdf

输入格式

交易 CSV
date,amount,description,category
2024-01-15,45.99,Amazon Purchase,Shopping
2024-01-16,12.50,Starbucks,Food & Dining
2024-01-17,150.00,Electric Company,Utilities
自定义类别(JSON)
{
  "Food & Dining": ["starbucks", "mcdonalds", "restaurant", "uber eats"],
  "Transportation": ["uber", "lyft", "gas station", "shell"],
  "Shopping": ["amazon", "walmart", "target"],
  "Utilities": ["electric", "water", "gas", "internet"]
}
预算目标(JSON)
{
  "Food & Dining": 500,
  "Transportation": 200,
  "Shopping": 300,
  "Utilities": 250,
  "Entertainment": 150
}

API 参考

BudgetAnalyzer 类
class BudgetAnalyzer:
    def __init__(self)

    # Data Loading
    def load_csv(self, filepath: str, date_col: str, amount_col: str,
                 description_col: str = None, category_col: str = None) -> 'BudgetAnalyzer'
    def load_dataframe(self, df: pd.DataFrame) -> 'BudgetAnalyzer'

    # Categorization
    def set_categories(self, categories: Dict[str, List[str]]) -> 'BudgetAnalyzer'
    def auto_categorize(self) -> 'BudgetAnalyzer'

    # Analysis
    def analyze(self) -> Dict  # Full summary
    def by_category(self) -> pd.DataFrame
    def by_month(self) -> pd.DataFrame
    def by_day_of_week(self) -> pd.DataFrame
    def top_expenses(self, n: int = 10) -> pd.DataFrame
    def recurring_expenses(self) -> pd.DataFrame

    # Comparison
    def compare_periods(self, period1: str, period2: str) -> Dict
    def year_over_year(self) -> pd.DataFrame

    # Budgeting
    def set_budget(self, budget: Dict[str, float]) -> 'BudgetAnalyzer'
    def budget_vs_actual(self) -> pd.DataFrame
    def budget_alerts(self) -> List[Dict]

    # Insights
    def get_recommendations(self) -> List[str]
    def spending_score(self) -> Dict

    # Visualization
    def plot_categories(self, output: str) -> str
    def plot_trends(self, output: str) -> str
    def plot_budget_comparison(self, output: str) -> str

    # Export
    def generate_report(self, output: str, format: str = "pdf") -> str
    def to_csv(self, output: str) -> str

分析功能

汇总统计
summary = analyzer.analyze()
# Returns:
# {
#     "total_spent": 2500.00,
#     "transaction_count": 45,
#     "date_range": {"start": "2024-01-01", "end": "2024-01-31"},
#     "average_transaction": 55.56,
#     "largest_expense": {"amount": 500, "description": "Rent"},
#     "categories": {"Food": 450, "Transport": 200, ...}
# }
类别细分
categories = analyzer.by_category()
# Returns DataFrame:
#   category        | amount  | percentage | count
#   Food & Dining   | 450.00  | 18.0%      | 15
#   Transportation  | 200.00  | 8.0%       | 8
#   ...
月度趋势
monthly = analyzer.by_month()
# Returns DataFrame:
#   month    | total    | avg_transaction | count
#   2024-01  | 2500.00  | 55.56          | 45
#   2024-02  | 2800.00  | 60.87          | 46
周期比较
comparison = analyzer.compare_periods("2024-01", "2024-02")
# Returns:
# {
#     "period1_total": 2500.00,
#     "period2_total": 2800.00,
#     "difference": 300.00,
#     "percent_change": 12.0,
#     "category_changes": {
#         "Food": {"change": 50, "percent": 11.1},
#         ...
#     }
# }

预算跟踪

设置预算目标
analyzer.set_budget({
    "Food & Dining": 500,
    "Transportation": 200,
    "Shopping": 300
})
预算与实际对比
comparison = analyzer.budget_vs_actual()
# Returns DataFrame:
#   category        | budget | actual | difference | status
#   Food & Dining   | 500    | 450    | 50         | under
#   Transportation  | 200    | 250    | -50        | over
预算提醒
alerts = analyzer.budget_alerts()
# Returns:
# [
#     {"category": "Transportation", "status": "over", "amount": 250, "budget": 200, "percent_over": 25},
#     {"category": "Shopping", "status": "warning", "amount": 280, "budget": 300, "percent_used": 93}
# ]

建议引擎

recommendations = analyzer.get_recommendations()
# Returns:
# [
#     "Food & Dining spending increased 15% from last month. Consider meal prepping.",
#     "You have 3 subscription services totaling $45/month. Review for unused subscriptions.",
#     "Transportation costs are 25% over budget. Consider carpooling or public transit.",
#     "Top merchant: Amazon ($350). Set spending limits for online shopping."
# ]

支出评分

score = analyzer.spending_score()
# Returns:
# {
#     "overall_score": 72,  # 0-100
#     "factors": {
#         "budget_adherence": 65,
#         "spending_consistency": 80,
#         "savings_rate": 70
#     },
#     "grade": "B",
#     "summary": "Good spending habits with room for improvement in budget adherence."
# }

自动分类

内置类别模式:

DEFAULT_CATEGORIES = {
    "Food & Dining": ["restaurant", "cafe", "starbucks", "mcdonald", "uber eats", "doordash"],
    "Transportation": ["uber", "lyft", "gas", "shell", "chevron", "parking"],
    "Shopping": ["amazon", "walmart", "target", "costco", "best buy"],
    "Utilities": ["electric", "water", "gas", "internet", "phone", "verizon"],
    "Entertainment": ["netflix", "spotify", "hulu", "movie", "theater"],
    "Healthcare": ["pharmacy", "cvs", "walgreens", "doctor", "hospital"],
    "Travel": ["airline", "hotel", "airbnb", "booking"],
    "Subscriptions": ["subscription", "membership", "monthly"]
}

可视化

类别饼图
analyzer.plot_categories("categories.png")
# Creates pie chart of spending by category
支出趋势
analyzer.plot_trends("trends.png")
# Creates line chart of monthly spending over time
预算比较
analyzer.plot_budget_comparison("budget.png")
# Creates bar chart comparing budget vs actual by category

报告生成

PDF 报告
analyzer.generate_report("report.pdf")
# Includes:
# - Executive summary
# - Category breakdown with charts
# - Monthly trends
# - Top expenses
# - Budget vs actual (if set)
# - Recommendations
HTML 报告
analyzer.generate_report("report.html", format="html")
# Interactive HTML report with charts

工作流示例

个人财务回顾
analyzer = BudgetAnalyzer()
analyzer.load_csv("bank_transactions.csv",
                  date_col="Date",
                  amount_col="Amount",
                  description_col="Description")

# Auto-categorize transactions
analyzer.auto_categorize()

# Set monthly budget
analyzer.set_budget({
    "Food & Dining": 600,
    "Transportation": 250,
    "Entertainment": 200
})

# Get full analysis
print(analyzer.analyze())
print(analyzer.budget_vs_actual())
print(analyzer.get_recommendations())

# Generate report
analyzer.generate_report("monthly_review.pdf")
企业支出跟踪
analyzer = BudgetAnalyzer()
analyzer.load_csv("business_expenses.csv",
                  date_col="date",
                  amount_col="amount",
                  category_col="expense_type")

# Compare quarters
q1_vs_q2 = analyzer.compare_periods("2024-Q1", "2024-Q2")

# Top expense categories
top = analyzer.by_category().head(5)

# Generate report for accounting
analyzer.generate_report("quarterly_expenses.pdf")

依赖项

  • pandas>=2.0.0
  • numpy>=1.24.0
  • matplotlib>=3.7.0
  • reportlab>=4.0.0

评论

支持 Markdown