Py.Cafe

Coding-with-Adam/

dash-nyc-class-size-analysis

Average Class Size Analysis in NYC Boroughs

DocsPricing
  • Class_Size_Report_mini.csv
  • 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
# check out https://dash.plotly.com/ for documentation
# And check out https://py.cafe/maartenbreddels for more examples
from dash import Dash, Input, Output, callback, dcc, html
import dash_ag_grid as dag
import plotly.express as px
import pandas as pd

df = pd.read_csv("Class_Size_Report_mini.csv")
df['CLASS SIZE'] = pd.to_numeric(df['CLASS SIZE'], errors='coerce')


df_filtered = df.groupby(['BOROUGH','GRADE LEVEL'])[['CLASS SIZE']].mean().reset_index()
df_filtered['BOROUGH'] = df_filtered['BOROUGH'].replace({
    'X': 'Bronx',
    'R': 'Staten Island',
    'K': 'Brooklyn',
    'M': 'Manhattan',
    'Q': 'Queens'
})

fig = px.sunburst(df_filtered, path=['BOROUGH','GRADE LEVEL'], color='CLASS SIZE',
                  title="Average Class Size by Borough and Grade Level")
fig.layout.update(margin=dict(l=20, r=20, t=30, b=30))


grid = dag.AgGrid(
    rowData=df.to_dict("records"),
    columnDefs=[{"field": i, 'filter': True, 'sortable': True} for i in df.columns],
    dashGridOptions={"pagination": True},
)
app = Dash(__name__)
app.layout = html.Div(
    children=[
        dcc.Markdown(children="Title of Graph"),
        dcc.Graph(figure=fig),
        grid
    ]
)


# if __name__ == "__main__":
#     app.run(debug=True)