-
Notifications
You must be signed in to change notification settings - Fork 0
/
bike.py
54 lines (43 loc) · 1.66 KB
/
bike.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
# -*- coding: utf-8 -*-
"""bike.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1eEPCeyIuIMxnIMO1v92dSmFvaAGwSjeW
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import streamlit as st
import plotly.express as px
# Load data
day_df = pd.read_csv("day.csv")
hour_df = pd.read_csv("hour.csv")
# Data preprocessing
day_df.dropna(axis=0, inplace=True)
hour_df.dropna(axis=0, inplace=True)
var_yg_dipilih = ["mnth", "yr", "dteday", "weekday", "weathersit"]
day_df = day_df[var_yg_dipilih]
hour_sum = hour_df.groupby('dteday')['hr'].sum().reset_index()
merge_df = pd.merge(day_df, hour_sum, on='dteday', how='left')
bike_df = merge_df.rename(columns={
"mnth": "month",
"yr": "year",
"dteday": "date",
"weekday": "day_of_week",
"weathersit": "weather_condition",
"hr": "hour"
})
jam_terbanyak = bike_df.sort_values(by='date', ascending=False)
top5_jam_terbanyak = jam_terbanyak.head(5)
weathersit_nilai = bike_df['weather_condition'].value_counts().rename({1: 'Clear', 2: 'Mist + Cloudy', 3: 'Light Snow/Rain', 4: 'Heavy Rain'})
# Build Streamlit App
st.title("Bike Sharing Dataset")
# Top 5 Hour Barplot
st.subheader("5 Hari Tertinggi dengan Jumlah Jam Rental Terbanyak")
fig_top5_hour = px.bar(top5_jam_terbanyak, x='date', y='hour', labels={'date': 'Tanggal', 'hour': 'Total Jam'})
st.plotly_chart(fig_top5_hour)
# Weather Barplot
st.subheader("Frekuensi Penyewaan Sepeda Terhadap Kondisi Cuaca")
fig_weather = px.bar(x=weathersit_nilai.index, y=weathersit_nilai.values, labels={'x': 'Kondisi Cuaca', 'y': 'Frekuensi'})
st.plotly_chart(fig_weather)