forked from Hamza-Hanif-Mir2000/DataAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
103 lines (86 loc) · 3.78 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import pandas as pd
import plotly.express as px
import streamlit as st
st.set_page_config(page_title="Sales Dashboard",
page_icon=":bar_chart:",
layout="wide",
)
def getDataFromExcel():
dF = pd.read_excel(
io='supermarkt_sales.xlsx',
engine='openpyxl',
sheet_name='Sales',
skiprows=3,
nrows=1000,
)
dF["hour"] = pd.to_datetime(dF["Time"], format="%H:%M:%S").dt.hour
return dF
dF = getDataFromExcel()
st.sidebar.header("Select the Filter here")
cityName = st.sidebar.multiselect(label="Select city name here:",
options=dF["City"].unique(),
default=dF["City"].unique()
)
customerType = st.sidebar.multiselect(label="Select customer type here:",
options=dF["Customer_type"].unique(),
default=dF["Customer_type"].unique()
)
gender = st.sidebar.multiselect(label="Select customer gender here:",
options=dF["Gender"].unique(),
default=dF["Gender"].unique()
)
selectionQuery = dF.query("City == @cityName & Customer_type == @customerType & Gender == @gender")
# -------- main Page --------#
st.title(":bar_chart: Sales Dashboard")
st.markdown("---")
totalSum = int(selectionQuery["Total"].sum())
averageRating = round(selectionQuery["Rating"].mean(), 1)
starRating = ":star:" * int(round(averageRating, 0))
averageSaleTransaction = round(selectionQuery["Total"].mean(), 2)
leftCol, middleCol, rightCol = st.columns(3)
with leftCol:
st.subheader("Total Sum: ")
st.subheader("US $ " + str('{:,}'.format(totalSum)))
with middleCol:
st.subheader("Average Rating: ")
st.subheader(str(averageRating) + " " + str(starRating))
with rightCol:
st.subheader("Average Sale By transaction: ")
st.subheader("US $" + str('{:,}'.format(averageSaleTransaction)))
st.markdown("---")
# ----- visual Stuff -----#
salesByProduct = selectionQuery.groupby(by=["Product line"]).sum()[["Total"]].sort_values(by="Total")
barChartByProductLine = px.bar(salesByProduct,
x="Total",
y=salesByProduct.index,
orientation='h',
title="<b>Sales by Product Line</b>",
color_discrete_sequence=["#0083B8"] * len(salesByProduct),
template="plotly_white",
)
barChartByProductLine.update_layout(plot_bgcolor="rgba(0,0,0,0)",
xaxis=(dict(showgrid=False)))
salesByTime = selectionQuery.groupby(by=["hour"]).sum()[["Total"]]
barChartByHour = px.bar(salesByTime,
x=salesByTime.index,
y="Total",
title="<b>Sales by hour</b>",
color_discrete_sequence=["#0083B8"] * len(salesByTime),
template="plotly_white",
)
barChartByHour.update_layout(plot_bgcolor="rgba(0,0,0,0)",
xaxis=(dict(showgrid=False)))
leftCOL, rightCOL = st.columns(2)
with leftCOL:
st.plotly_chart(barChartByProductLine)
with rightCOL:
st.plotly_chart(barChartByHour)
# ---- 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)