Notes:
-
What problem does it solve?: Helps businesses plan and track their budgets, comparing actual vs. planned expenses.
-
How can businesses benefit from customizing the code?: Businesses can tailor budget categories, add multiple forecasts, and track variances.
-
How can businesses adopt the solution further?: Extend to integrate with accounting software to track spending in real-time.
Actual Python Code:
import pandas as pd
class BudgetPlanner:
def __init__(self, categories, planned_amounts, actual_amounts):
self.categories = categories
self.planned_amounts = planned_amounts
self.actual_amounts = actual_amounts
def create_budget_df(self):
data = {
'Category': self.categories,
'Planned Amount': self.planned_amounts,
'Actual Amount': self.actual_amounts,
'Variance': [p - a for p, a in zip(self.planned_amounts, self.actual_amounts)]
}
return pd.DataFrame(data)
def analyze_budget(self):
df = self.create_budget_df()
print("Budget Overview:")
print(df)
total_planned = df['Planned Amount'].sum()
total_actual = df['Actual Amount'].sum()
total_variance = df['Variance'].sum()
print(f"\nTotal Planned: ${total_planned:.2f}")
print(f"Total Actual: ${total_actual:.2f}")
print(f"Total Variance: ${total_variance:.2f}")
return df
# Example usage
categories = ['Marketing', 'Salaries', 'Operations']
planned = [5000, 30000, 12000]
actual = [4500, 29000, 12500]
budget = BudgetPlanner(categories, planned, actual)
budget.analyze_budget()
No comments:
Post a Comment