I wanna show only one " Building " under middle bar graph.
import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
import altair as alt
import plotly.graph_objects as go
from query import *
st.set_page_config(
page_title=âTrue Digital Park Reportâ,
layout=âwideâ,
page_icon=ââ
)
@st.cache_data
def get_data_property():
cols = [âEvent_startâ, âYearâ, âMonthâ, âQuarterâ, âBuildingâ]
return pd.read_csv( âdata/true_data.csvâ, parse_dates=[âEvent_startâ])
df = get_data_property()
year_filter = st.selectbox(âSelect the Yearâ, pd.unique(df[âYearâ]))
df = df[df[âYearâ] == year_filter]
df
df[âMonth_of_Yearâ] = df[âEvent_startâ].dt.month
df[âDayâ] = df[âEvent_startâ].dt.day_name()
df[âDay_of_weekâ] = df[âEvent_startâ].dt.day_of_week
year=st.sidebar.multiselect(
âSELECT YEARâ,
options=df.sort_values(by=âYearâ, ascending=True)[âYearâ].unique(),
default=df.sort_values(by=âYearâ, ascending=True)[âYearâ].unique()
)
month=st.sidebar.multiselect(
âSELECT MONTHâ,
options=df.sort_values(by=âMonth_of_Yearâ, ascending=True)[âMonthâ].unique(),
default=df.sort_values(by=âMonth_of_Yearâ, ascending=True)[âMonthâ].unique()
)
quarter=st.sidebar.multiselect(
âSELECT QUARTORâ,
options=df.sort_values(by=âQuarterâ, ascending=True)[âQuarterâ].unique(),
default=df.sort_values(by=âQuarterâ, ascending=True)[âQuarterâ].unique(),
)
building=st.sidebar.multiselect(
âSELECT Buildingâ,
options=df.sort_values(by=âBuildingâ, ascending=True)[âBuildingâ].unique(),
default=df.sort_values(by=âBuildingâ, ascending=True)[âBuildingâ].unique(),
)
day=st.sidebar.multiselect(
âSELECT Day of Weekâ,
options=df.sort_values(by=âDay_of_weekâ, ascending=True)[âDayâ].unique(),
default=df.sort_values(by=âDay_of_weekâ, ascending=True)[âDayâ].unique(),
)
df_selection = df.query(
âYear==@year & Month==@month & Quarter==@quarter & Building==@building & Day==@dayâ
)
df2 = df_selection.groupby([âQuarterâ, âMonthâ, âYearâ])[âEvent_nameâ].count().reset_index()
df3 = df_selection.groupby([âYearâ, âBuildingâ])[âEvent_nameâ].count().reset_index()
df4 = df_selection.groupby([âMonthâ, âDayâ])[âEvent_nameâ].count().reset_index()
df5 = df_selection.groupby([ âMonthâ, âYearâ, âType_eventâ])[âEvent_nameâ].count().reset_index()
ordered_months = [âJanuaryâ, âFebruaryâ, âMarchâ, âAprilâ, âMayâ, âJuneâ,
âJulyâ, âAugustâ, âSeptemberâ, âOctoberâ, âNovemberâ, âDecemberâ]
DF 2
for axis in fig.layout:
if axis.startswith(âxaxisâ) or axis.startswith(âyaxisâ):
fig.layout[axis].title = ââ
def month_and_quarter():
fig = px.bar(
df2,
x=âQuarterâ,
y=âMonthâ,
color=âMonthâ,
# facet_col=âYearâ,
text_auto=â.2sâ,
# barmode=âgroupâ,
labels={âEvent_nameâ: âEvent Countâ},
category_orders={âMonthâ: [âJanuaryâ, âFebruaryâ, âMarchâ, âAprilâ, âMayâ, âJuneâ, âJulyâ, âAugustâ, âSeptemberâ, âOctoberâ, âNovemberâ, âDecemberâ]},
title=âNumber of event by month or quarterâ
)
fig.update_layout(showlegend=True)
for axis in fig.layout:
if axis.startswith(âxaxisâ) or axis.startswith(âyaxisâ):
fig.layout[axis].title = ââ
fig.update_layout(
xaxis_title=âx Axis Titleâ,
yaxis_title=ây Axis Titleâ,
)
fig.update_layout(
xaxis=dict(title=âCategoriesâ),
legend_title=âLegend Titleâ,
)
st.plotly_chart(fig, use_container_width=True)
month_and_quarter()
DF 3
def month_and_quarter():
fig = px.bar(
df3,
x=âBuildingâ,
y=âEvent_nameâ,
color=âBuildingâ,
facet_col=âYearâ,
text_auto=â.2sâ,
labels={âEvent_nameâ: âEvent Countâ},
title=âNumber of event by year compare with another yeartâ
)
for axis in fig.layout:
if axis.startswith(âxaxisâ) or axis.startswith(âyaxisâ):
fig.layout[axis].title = ââ
fig.add_annotation(x=0.5, y=-0.1,xref=âpaperâ,yref=âpaperâ,
text=âBuildingâ,
showarrow=False,)
fig.update_layout(showlegend=True)
st.plotly_chart(fig, use_container_width=True)
month_and_quarter()
DF 4
def month_and_quarter():
fig = px.bar(
df4,
x=âEvent_nameâ,
y=âDayâ,
color=âDayâ,
facet_col=âMonthâ,
text_auto=â.2sâ,
labels={âEvent_nameâ: âEvent Countâ},
category_orders={âDayâ: [âMondayâ, âTuesdayâ, âWednesdayâ, âThursdayâ, âFridayâ, âSaturdayâ, âSundayâ]},
title=âNumber of event in each day by monthâ
)
for axis in fig.layout:
if axis.startswith(âxaxisâ) or axis.startswith(âyaxisâ):
fig.layout[axis].title = ââ
fig.update_layout(showlegend=True)
st.plotly_chart(fig, use_container_width=True)
month_and_quarter()
DF 4
def month_and_quarter2():
fig = px.bar(
df4,
x=âDayâ,
y=âEvent_nameâ,
color=âDayâ,
facet_col=âMonthâ,
text_auto=â.2sâ,
labels={âEvent_nameâ: âEvent Countâ},
category_orders={
âDayâ: [âMondayâ, âTuesdayâ, âWednesdayâ, âThursdayâ, âFridayâ, âSaturdayâ, âSundayâ],
âMonthâ: [âJanuaryâ, âFebruaryâ, âMarchâ, âAprilâ, âMayâ, âJuneâ, âJulyâ, âAugustâ, âSeptemberâ, âOctoberâ, âNovemberâ, âDecemberâ]
},
title=âNumber of event in each day by monthâ
)
for axis in fig.layout:
if axis.startswith(âxaxisâ) or axis.startswith(âyaxisâ):
fig.layout[axis].title = ââ
fig.update_layout(showlegend=True)
st.plotly_chart(fig, use_container_width=True)
month_and_quarter2()
DF 5
def event_type_of_year():
fig = px.bar(
df5,
height=800,
x=âEvent_nameâ,
y=âType_eventâ,
color=âType_eventâ,
facet_col=âYearâ,
text_auto=â.2sâ,
labels={âType_eventâ: âType Eventâ, âEvent_nameâ: âEvent Countâ},
title=âType of event by monthâ,
)
for axis in fig.layout:
if axis.startswith(âxaxisâ) or axis.startswith(âyaxisâ):
fig.layout[axis].title = ââ
fig.update_layout(showlegend=False)
st.plotly_chart(fig, use_container_width=True)
event_type_of_year()
def event_type_of_month():
fig = px.bar(
df5,
height=700,
x=[âMonthâ, âEvent_nameâ],
y=âType_eventâ,
color=âType_eventâ,
facet_col=âMonthâ,
text_auto=â.2sâ,
labels={âType_eventâ: âType Eventâ, âEvent_nameâ: âEvent Countâ},
category_orders={
âMonthâ: [âJanuaryâ, âFebruaryâ, âMarchâ, âAprilâ, âMayâ, âJuneâ, âJulyâ, âAugustâ, âSeptemberâ, âOctoberâ, âNovemberâ, âDecemberâ]
},
title=âType of event by monthâ,
)
for axis in fig.layout:
if axis.startswith(âxaxisâ) or axis.startswith(âyaxisâ):
fig.layout[axis].title = ââ
fig.update_layout(showlegend=False)
st.plotly_chart(fig, use_container_width=True)
event_type_of_month()