Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J-72
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
22_23-J-72
22_23-J-72
Commits
7a7113c1
Commit
7a7113c1
authored
Feb 08, 2023
by
Malinda perera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
c65ef544
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
127 additions
and
0 deletions
+127
-0
app.py.txt
app.py.txt
+127
-0
No files found.
app.py.txt
0 → 100644
View file @
7a7113c1
# @Email: contact@pythonandvba.com
# @Website: https://pythonandvba.com
# @YouTube: https://youtube.com/c/CodingIsFun
# @Project: Sales Dashboard w/ Streamlit
import pandas as pd # pip install pandas openpyxl
import plotly.express as px # pip install plotly-express
import streamlit as st # pip install streamlit
# emojis: https://www.webfx.com/tools/emoji-cheat-sheet/
st.set_page_config(page_title="crime report statistics dashboard", page_icon=":bar_chart:", layout="wide")
# ---- READ EXCEL ----
@st.cache
def get_data_from_excel():
df = pd.read_excel(
io="crime_dataset.xlsx",
engine="openpyxl",
sheet_name="Sales",
skiprows=3,
usecols="B:R",
nrows=1000,
)
# Add 'hour' column to dataframe
df["hour"] = pd.to_datetime(df["Time"], format="%H:%M:%S").dt.hour
return df
df = get_data_from_excel()
# ---- SIDEBAR ----
st.sidebar.header("Please Filter Here:")
city = st.sidebar.multiselect(
"Select the City:",
options=df["City"].unique(),
default=df["City"].unique()
)
jailed_or_not = st.sidebar.multiselect(
"Select the criminal Type:",
options=df["jailed_or_not"].unique(),
default=df["jailed_or_not"].unique(),
)
gender = st.sidebar.multiselect(
"Select the Gender:",
options=df["Gender"].unique(),
default=df["Gender"].unique()
)
df_selection = df.query(
"City == @city & jailed_or_not ==@jailed_or_not & Gender == @gender"
)
# ---- MAINPAGE ----
st.title(":bar_chart: crime report statistics dashboard")
st.markdown("##")
# # TOP KPI's
# total_sales = int(df_selection["Total"].sum())
# average_rating = round(df_selection["Rating"].mean(), 1)
# star_rating = ":star:" * int(round(average_rating, 0))
# average_sale_by_transaction = round(df_selection["Total"].mean(), 2)
#
# left_column, middle_column, right_column = st.columns(3)
# with left_column:
# st.subheader("Total Sales:")
# st.subheader(f"US $ {total_sales:,}")
# with middle_column:
# st.subheader("Average Rating:")
# st.subheader(f"{average_rating} {star_rating}")
# with right_column:
# st.subheader("Average Sales Per Transaction:")
# st.subheader(f"US $ {average_sale_by_transaction}")
st.markdown("""---""")
# SALES BY PRODUCT LINE [BAR CHART]
sales_by_product_line = (
df_selection.groupby(by=["crime_catog"]).sum()[["Total"]].sort_values(by="Total")
)
fig_product_sales = px.bar(
sales_by_product_line,
x="Total",
y=sales_by_product_line.index,
orientation="h",
title="<b>crimes by category</b>",
color_discrete_sequence=["#0083B8"] * len(sales_by_product_line),
template="plotly_white",
)
fig_product_sales.update_layout(
plot_bgcolor="rgba(0,0,0,0)",
xaxis=(dict(showgrid=False))
)
# SALES BY HOUR [BAR CHART]
sales_by_hour = df_selection.groupby(by=["month"]).sum()[["Total"]]
fig_hourly_sales = px.bar(
sales_by_hour,
x=sales_by_hour.index,
y="Total",
title="<b>crimes by month</b>",
color_discrete_sequence=["#0083B8"] * len(sales_by_hour),
template="plotly_white",
)
fig_hourly_sales.update_layout(
xaxis=dict(tickmode="linear"),
plot_bgcolor="rgba(0,0,0,0)",
yaxis=(dict(showgrid=False)),
)
left_column, right_column = st.columns(2)
left_column.plotly_chart(fig_hourly_sales, use_container_width=True)
right_column.plotly_chart(fig_product_sales, use_container_width=True)
# ---- HIDE STREAMLIT STYLE ----
hide_st_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}
</style>
"""
st.markdown(hide_st_style, unsafe_allow_html=True)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment