-
Notifications
You must be signed in to change notification settings - Fork 58
/
app.py
131 lines (112 loc) · 4.84 KB
/
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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import streamlit as st
import pandas as pd
import datetime
from PIL import Image
import plotly.express as px
import plotly.graph_objects as go
print("Hello Learners")
# reading the data from excel file
df = pd.read_excel("Adidas.xlsx")
st.set_page_config(layout="wide")
st.markdown('<style>div.block-container{padding-top:1rem;}</style>', unsafe_allow_html=True)
image = Image.open('adidas-logo.jpg')
col1, col2 = st.columns([0.1,0.9])
with col1:
st.image(image,width=100)
html_title = """
<style>
.title-test {
font-weight:bold;
padding:5px;
border-radius:6px;
}
</style>
<center><h1 class="title-test">Adidas Interactive Sales Dashboard</h1></center>"""
with col2:
st.markdown(html_title, unsafe_allow_html=True)
col3, col4, col5 = st.columns([0.1,0.45,0.45])
with col3:
box_date = str(datetime.datetime.now().strftime("%d %B %Y"))
st.write(f"Last updated by: \n {box_date}")
with col4:
fig = px.bar(df, x = "Retailer", y = "TotalSales", labels={"TotalSales" : "Total Sales {$}"},
title = "Total Sales by Retailer", hover_data=["TotalSales"],
template="gridon",height=500)
st.plotly_chart(fig,use_container_width=True)
_, view1, dwn1, view2, dwn2 = st.columns([0.15,0.20,0.20,0.20,0.20])
with view1:
expander = st.expander("Retailer wise Sales")
data = df[["Retailer","TotalSales"]].groupby(by="Retailer")["TotalSales"].sum()
expander.write(data)
with dwn1:
st.download_button("Get Data", data = data.to_csv().encode("utf-8"),
file_name="RetailerSales.csv", mime="text/csv")
df["Month_Year"] = df["InvoiceDate"].dt.strftime("%b'%y")
result = df.groupby(by = df["Month_Year"])["TotalSales"].sum().reset_index()
with col5:
fig1 = px.line(result, x = "Month_Year", y = "TotalSales", title="Total Sales Over Time",
template="gridon")
st.plotly_chart(fig1,use_container_width=True)
with view2:
expander = st.expander("Monthly Sales")
data = result
expander.write(data)
with dwn2:
st.download_button("Get Data", data = result.to_csv().encode("utf-8"),
file_name="Monthly Sales.csv", mime="text/csv")
st.divider()
result1 = df.groupby(by="State")[["TotalSales","UnitsSold"]].sum().reset_index()
# add the units sold as a line chart on a secondary y-axis
fig3 = go.Figure()
fig3.add_trace(go.Bar(x = result1["State"], y = result1["TotalSales"], name = "Total Sales"))
fig3.add_trace(go.Scatter(x=result1["State"], y = result1["UnitsSold"], mode = "lines",
name ="Units Sold", yaxis="y2"))
fig3.update_layout(
title = "Total Sales and Units Sold by State",
xaxis = dict(title="State"),
yaxis = dict(title="Total Sales", showgrid = False),
yaxis2 = dict(title="Units Sold", overlaying = "y", side = "right"),
template = "gridon",
legend = dict(x=1,y=1.1)
)
_, col6 = st.columns([0.1,1])
with col6:
st.plotly_chart(fig3,use_container_width=True)
_, view3, dwn3 = st.columns([0.5,0.45,0.45])
with view3:
expander = st.expander("View Data for Sales by Units Sold")
expander.write(result1)
with dwn3:
st.download_button("Get Data", data = result1.to_csv().encode("utf-8"),
file_name = "Sales_by_UnitsSold.csv", mime="text/csv")
st.divider()
_, col7 = st.columns([0.1,1])
treemap = df[["Region","City","TotalSales"]].groupby(by = ["Region","City"])["TotalSales"].sum().reset_index()
def format_sales(value):
if value >= 0:
return '{:.2f} Lakh'.format(value / 1_000_00)
treemap["TotalSales (Formatted)"] = treemap["TotalSales"].apply(format_sales)
fig4 = px.treemap(treemap, path = ["Region","City"], values = "TotalSales",
hover_name = "TotalSales (Formatted)",
hover_data = ["TotalSales (Formatted)"],
color = "City", height = 700, width = 600)
fig4.update_traces(textinfo="label+value")
with col7:
st.subheader(":point_right: Total Sales by Region and City in Treemap")
st.plotly_chart(fig4,use_container_width=True)
_, view4, dwn4 = st.columns([0.5,0.45,0.45])
with view4:
result2 = df[["Region","City","TotalSales"]].groupby(by=["Region","City"])["TotalSales"].sum()
expander = st.expander("View data for Total Sales by Region and City")
expander.write(result2)
with dwn4:
st.download_button("Get Data", data = result2.to_csv().encode("utf-8"),
file_name="Sales_by_Region.csv", mime="text.csv")
_,view5, dwn5 = st.columns([0.5,0.45,0.45])
with view5:
expander = st.expander("View Sales Raw Data")
expander.write(df)
with dwn5:
st.download_button("Get Raw Data", data = df.to_csv().encode("utf-8"),
file_name = "SalesRawData.csv", mime="text/csv")
st.divider()