-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmini_project_part1.py
More file actions
41 lines (32 loc) · 1.46 KB
/
mini_project_part1.py
File metadata and controls
41 lines (32 loc) · 1.46 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
# Import library
import datetime
import pandas as pd
import matplotlib.pyplot as plt
class Dqlab_matplotlib:
def __init__(self):
pass
def read_dataset(self, link):
dataset = pd.read_csv(link)
return dataset
def prepare_dataset(self, dataset):
# Buat kolom order_month
dataset['order_month'] = dataset['order_date'].apply(lambda x: datetime.datetime.strptime(x, "%Y-%m-%d").strftime('%Y-%m'))
# Buat kolom gmv
dataset['gmv'] = dataset['item_price'] * dataset['quantity']
return dataset
def graph(self, dataset):
# Plot grafik sesuai dengan instruksi
plt.figure(figsize=(10, 5))
dataset[dataset['order_month']=='2019-12'].groupby(['order_date'])['customer_id'].nunique().plot(color='red', marker='.', linewidth=2)
plt.title('Daily Number of Customers - December 2019', loc='left', pad=30, fontsize=20, color='orange')
plt.xlabel('Order Date', fontsize=15, color='blue')
plt.ylabel('Number of Customers', fontsize=15, color='blue')
plt.grid(color='darkgray', linestyle=':', linewidth=0.5)
plt.ylim(ymin=0)
plt.savefig('Daily number of customers on Desember.png')
plt.show()
link = 'https://dqlab-dataset.s3-ap-southeast-1.amazonaws.com/retail_raw_reduced.csv'
app = Dqlab_matplotlib()
data = app.read_dataset(link)
final_data = app.prepare_dataset(data)
app.graph(final_data)