Py.Cafe

savitharachuri/

dash-nyc-animal-complaints-analysis

NYC 311 Animal Complaints Analysis with Dash

DocsPricing
  • 311_Animals_short.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
44
45
46
47
48
49
50
51
# 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 plotly.express as px
import pandas as pd

df = pd.read_csv("311_Animals_short.csv")
df['Created Date'] = pd.to_datetime(df['Created Date'])
df['Closed Date'] = pd.to_datetime(df['Closed Date'])
df['Resolution Action Updated Date'] = pd.to_datetime(df['Resolution Action Updated Date'])
df['month_int'] = df['Created Date'].dt.month
df['week'] = df['Created Date'].dt.isocalendar().week
df.sort_values(by='Created Date')
df['weekofmonth'] = df['Created Date'].apply(lambda d: (d.day-1) // 7 + 1)
df['day'] = df['Created Date'].dt.dayofweek.map({
    0: 'Monday',
    1: 'Tuesday',
    2: 'Wednesday',
    3: 'Thursday',
    4: 'Friday',
    5: 'Saturday',
    6: 'Sunday'
})
df['month_name'] = df['Created Date'].dt.month_name()
fig = px.histogram(df, x="month_name", category_orders = dict(month_name=['January', 'February', 'March']), labels = {'month_name':'MONTH'},  text_auto=True)
fig.show()

app = Dash(__name__)
md = """
# Dash demo

See [The dash examples index](https://dash-example-index.herokuapp.com/) for more examples.
"""

app.layout = html.Div(
    children=[
        #dcc.Markdown(children=md, link_target="_blank"),
        #dcc.Dropdown(id="dropdown", options=["red", "green", "blue", "orange"]),
        #dcc.Markdown(id="markdown", children=["## Hello World"]),
        dcc.Graph(figure=fig),
    ]
)


@callback(
    Output("markdown", "style"),
    Input("dropdown", "value"),
)
def update_markdown_style(color):
    return {"color": color}