-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclearning.py
More file actions
184 lines (133 loc) · 3.48 KB
/
clearning.py
File metadata and controls
184 lines (133 loc) · 3.48 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# %% [markdown]
# # Proyek Analisis Data: [Input Nama Dataset]
# - **Nama:** Aditiya Ihzar Eka Prayogo
# - **Email:** adit.ihzar@gmail.com
# - **ID Dicoding:** aditPrayogo
# %% [markdown]
# ## Menentukan Pertanyaan Bisnis
# %% [markdown]
# - Kapan waktu puncak peminjaman sepeda terjadi dalam sehari?
# - Apa pengaruh cuaca dan suhu terhadap jumlah peminjam sepeda?
# - Apakah hari kerja dan hari libur memengaruhi peminjaman?
# %% [markdown]
# ## Import Semua Packages/Library yang Digunakan
# %%
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# %% [markdown]
# ## Data Wrangling
# %% [markdown]
# ### Gathering Data
# %%
# Load Tabel Day
day_df = pd.read_csv('data/day.csv')
day_df.head()
# %%
# Load Table Hour
hour_df = pd.read_csv('data/hour.csv')
hour_df.head()
# %% [markdown]
# **Insight:**
# - xxx
# - xxx
# %% [markdown]
# ### Assessing Data
# %%
hour_df.info()
day_df.info()
# %%
# Checking missing values in hour_df
print(hour_df.isnull().sum())
# %%
# Check for missing values in day_df
print(day_df.isnull().sum())
# %%
# Check for duplicates in hour_df
print(f"Number of duplicate rows in hour_df: {hour_df.duplicated().sum()}")
# %%
# Checking missing values in day_df
print(f"Number of duplicate rows in day_df: {day_df.duplicated().sum()}")
# %%
# Checking Statistical Summary hour_df
hour_df.describe()
# %%
# Checking Statistical Summary day_df
day_df.describe()
# %% [markdown]
# **Insight:**
# - xxx
# - xxx
# %% [markdown]
# ### Cleaning Data
# %%
# Menghapus kolom yang tidak relevan
hour_df.drop(columns=['instant'], inplace=True)
day_df.drop(columns=['instant'], inplace=True)
# %%
# Mengubah kolom kategori ke tipe data kategorikal
kategori_cols = ['season', 'yr', 'mnth', 'holiday', 'weekday', 'workingday', 'weathersit', 'hr']
for col in kategori_cols:
if col in hour_df.columns:
hour_df[col] = hour_df[col].astype('category')
for col in kategori_cols:
if col in day_df.columns:
day_df[col] = day_df[col].astype('category')
# %%
# Cek apakah total pengguna sesuai
assert (day_df['casual'] + day_df['registered'] == day_df['cnt']).all()
assert (hour_df['casual'] + hour_df['registered'] == hour_df['cnt']).all()
# %%
# Menggunakan IQR untuk mendeteksi outlier pada kolom cnt
Q1 = hour_df['cnt'].quantile(0.25)
Q3 = hour_df['cnt'].quantile(0.75)
IQR = Q3 - Q1
outliers = hour_df[(hour_df['cnt'] < Q1 - 1.5*IQR) | (hour_df['cnt'] > Q3 + 1.5*IQR)]
print(f"Jumlah outlier cnt: {len(outliers)}")
# %%
hour_df['dteday'] = pd.to_datetime(hour_df['dteday'])
day_df['dteday'] = pd.to_datetime(day_df['dteday'])
# Cek duplikat berdasarkan tanggal & jam
duplicates = hour_df.duplicated(subset=['dteday', 'hr']).sum()
print(f'Duplikasi berdasarkan tanggal dan jam: {duplicates}')
# %%
hour_df['temp_celsius'] = hour_df['temp'] * 41
# %%
hour_df.rename(columns={'yr': 'year', 'mnth': 'month'}, inplace=True)
# %%
# Berapa banyak nilai windspeed = 0?
print((hour_df['windspeed'] == 0).sum())
# %% [markdown]
# **Insight:**
# - xxx
# - xxx
# %% [markdown]
# ## Exploratory Data Analysis (EDA)
# %% [markdown]
# ### Explore ...
# %%
# %% [markdown]
# **Insight:**
# - xxx
# - xxx
# %% [markdown]
# ## Visualization & Explanatory Analysis
# %% [markdown]
# ### Pertanyaan 1:
# %%
# %% [markdown]
# ### Pertanyaan 2:
# %%
# %% [markdown]
# **Insight:**
# - xxx
# - xxx
# %% [markdown]
# ## Analisis Lanjutan (Opsional)
# %%
# %% [markdown]
# ## Conclusion
# %% [markdown]
# - Conclution pertanyaan 1
# - Conclution pertanyaan 2