-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
151 lines (136 loc) · 6.25 KB
/
streamlit_app.py
File metadata and controls
151 lines (136 loc) · 6.25 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import streamlit as st
sns.set_theme(style='dark')
df = pd.read_csv("data.csv")
hours_df = pd.read_csv("hour.csv")
st.write("<h2 style='text-align: center;'>DASHBOARD BIKE SHARING 2011-2012</h2>", unsafe_allow_html=True)
st.markdown("<br><h3>Hi There!</h3>", unsafe_allow_html=True)
st.markdown("<h5>Welcome to the bike Sharing Dashboard!</h5>", unsafe_allow_html=True)
st.markdown("<p>Navigate through the sidebar to access summaries of the data!</p>", unsafe_allow_html=True)
st.sidebar.title("Dashboard Navigation")
rental_2011 = df[df['yr'] == 0]['cnt'].sum()
rental_2012 = df[df['yr'] == 1]['cnt'].sum()
total = rental_2011 + rental_2012
persentase = round((rental_2012 - rental_2011) / rental_2011 * 100)
persentase = str(persentase) + "%"
col1, col2,col3 = st.columns(3)
with col1:
st.metric(label='Total Rental Sepeda', value=str(format(total,',d')))
with col2:
st.metric(label='Jumlah Rental Tahun 2011', value=str(format(rental_2011,',d')))
with col3:
st.metric(label='Jumlah Rental Tahun 2012', value=str(format(rental_2012,',d')), delta=persentase
)
st.sidebar.write("<br><b>Dataset Information</b>", unsafe_allow_html=True)
if st.sidebar.checkbox("Show Dataset per day"):
st.header("Dataset per day")
st.write(df)
if st.sidebar.checkbox("Show Dataset per hour"):
st.header("Data per hour" )
st.write(hours_df)
if st.sidebar.checkbox("Statistics"):
st.header("Statistics of days data" )
st.write(df.describe())
st.sidebar.write("<br><b>Dataset Visualization</b>", unsafe_allow_html=True)
if st.sidebar.checkbox("Rental for the year"):
st.header("Number of rental for the year 2011-2012")
df_date = df[["cnt","dteday"]].copy()
df_date['dteday'] = pd.to_datetime(df_date['dteday'].copy())
# Set the 'datetime_column' as the index of the DataFrame if it's not already
df_date.set_index('dteday', inplace=True)
# Resample the datetime series on 15-day intervals and apply any desired aggregation function (e.g., count)
result = df_date.resample('5D').mean()
fig, ax = plt.subplots(figsize=(16, 8))
plt.title("Number of Rental for the year 2011-2012", loc="center", fontsize=20)
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
ax.plot(result.index,result['cnt'])
st.pyplot(fig)
if st.sidebar.checkbox("Rental per month"):
mean =df.groupby('mnth')['cnt'].mean()
idxmin = (mean.idxmin())
idxmax = (mean.idxmax())
colors = ["#D3D3D3" for i in range(len(mean))]
colors[idxmin-1] = "#90CAF9"
colors[idxmax-1] = "#003366"
st.header("Number of Rental per month")
fig, ax = plt.subplots(figsize=(10, 5))
plt.bar(df.groupby('mnth')['cnt'].mean().index, df.groupby('mnth')['cnt'].mean().values,color = colors)
plt.title("Number of Rental per month", loc="center", fontsize=20)
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
st.pyplot(fig)
if st.sidebar.checkbox("Rental for each weather"):
st.header("Number of Rental for each weather")
fig, ax = plt.subplots(figsize=(10, 5))
mean = df.groupby('weathersit')['cnt'].mean()
idxmin = (mean.idxmin())
idxmax = (mean.idxmax())
colors = ["#90CAF9" if weather == idxmin else "#003366" if weather == idxmax else "#D3D3D3" for weather in mean.index]
plt.bar(mean.index, mean.values,color = colors)
plt.title("Number of Rental for each weather)", loc="center", fontsize=20)
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
st.pyplot(fig)
if st.sidebar.checkbox("Rental on temperature"):
st.header("Number of Rental based on temperature")
df_temp = df[["cnt","temp"]]
df_temp = df_temp.assign(temp_rounded = lambda x: (round(((x['temp'])*47)-8)*20)/20)
df_temp.describe()
fig, ax = plt.subplots(figsize=(10, 5))
stats = df_temp.groupby('temp_rounded')['cnt'].mean()
plt.plot(stats.index, stats.values)
plt.title("Number of Rental for temperature", loc="center", fontsize=20)
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
st.pyplot(fig)
if st.sidebar.checkbox("Rental for each season"):
st.header("Number of Rental for each season")
fig, ax = plt.subplots(figsize=(10, 5))
stats = df.groupby('season')['cnt'].mean()
idxmin = (stats.idxmin())
idxmax = (stats.idxmax())
colors = ["#90CAF9" if weather == idxmin else "#003366" if weather == idxmax else "#D3D3D3" for weather in stats.index]
plt.bar(stats.index, stats.values, color = colors)
plt.title("Number of Rental for each season", loc="center", fontsize=20)
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
st.pyplot(fig)
if st.sidebar.checkbox("Rental for holiday"):
st.header("Number of Rental for holiday")
fig, ax = plt.subplots(figsize=(10, 5))
stats = df.groupby('holiday')['cnt'].mean()
idxmin = (stats.idxmin())
idxmax = (stats.idxmax())
colors = ["#90CAF9" if weather == idxmin else "#003366" if weather == idxmax else "#D3D3D3" for weather in stats.index]
plt.bar(stats.index, stats.values,color = colors)
plt.title("Number of Rental for holiday", loc="center", fontsize=20)
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
st.pyplot(fig)
if st.sidebar.checkbox("Rental per hr"):
st.header("Number of Rental for holiday")
fig, ax = plt.subplots(figsize=(10, 5))
stats = hours_df.groupby('hr')['cnt'].mean()
idxmin = (stats.idxmin())
idxmax = (stats.idxmax())
colors = ["#90CAF9" if weather == idxmin else "#003366" if weather == idxmax else "#D3D3D3" for weather in stats.index]
plt.bar(stats.index, stats.values,color = colors)
plt.title("Number of Rental for each hr", loc="center", fontsize=20)
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
st.pyplot(fig)
if st.sidebar.checkbox("Rental for each weekday"):
st.header("Number of Rental for holiday")
fig, ax = plt.subplots(figsize=(10, 5))
stats = df.groupby('weekday')['cnt'].mean()
idxmin = (stats.idxmin())
idxmax = (stats.idxmax())
colors = ["#90CAF9" if weather == idxmin else "#003366" if weather == idxmax else "#D3D3D3" for weather in stats.index]
plt.bar(stats.index, stats.values,color = colors)
plt.title("Number of Rental for each weekday", loc="center", fontsize=20)
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
st.pyplot(fig)