Py.Cafe

ThomasD21M/

Wake County’s (North Carolina) budget

Wake Count Budget FY2023 Fund Top 15 Cost Center

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pandas as pd
import plotly.graph_objects as go
from dash import Dash, html, dcc
import requests

# Load cleaned budget data from GitHub
CSV_URL = "https://raw.githubusercontent.com/ProgInNameOnly/WakeCountyBudget/main/Budget_FY2023%20(1)_cleaned.csv"
df = pd.read_csv(CSV_URL)

# Filter for top 15 Cost Centers by total spend
top_centers = df.groupby("Cost_Center")["Actual_Amount"].sum().nlargest(15).index
filtered_df = df[df["Cost_Center"].isin(top_centers)]

# Group: Fund_Name ➝ Cost_Center
grouped = filtered_df.groupby(["Fund_Name", "Cost_Center"])["Actual_Amount"].sum().reset_index()

# Build label list
labels = pd.concat([grouped["Fund_Name"], grouped["Cost_Center"]]).unique().tolist()
label_index = {label: idx for idx, label in enumerate(labels)}

# Sankey source/target/value
source = grouped["Fund_Name"].map(label_index).tolist()
target = grouped["Cost_Center"].map(label_index).tolist()
value = grouped["Actual_Amount"].tolist()

# Build Sankey
fig = go.Figure(go.Sankey(
    node=dict(
        pad=15,
        thickness=20,
        line=dict(color="black", width=0.5),
        label=labels,
    ),
    link=dict(
        source=source,
        target=target,
        value=value
    )
))

fig.update_layout(title_text="Wake County Budget FY2023: Top 15 Cost Centers", font_size=12)

# Dash app layout
app = Dash(__name__)
app.layout = html.Div([
    html.H2("💰 Wake County Budget FY2023: Fund ➝ Top 15 Cost Centers", style={"textAlign": "center"}),
    dcc.Graph(figure=fig)
])

# For PyCafe
if __name__ == "__main__":
    app.run(debug=False, port=8050)