-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.Distribusi-kategorisasi-average-transaction-amount.py
38 lines (35 loc) · 1.85 KB
/
10.Distribusi-kategorisasi-average-transaction-amount.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
"""
Distribusi kategorisasi average transaction amount
Selanjutnya, akan melakukan visualisasi dari distribusi kategorisasi average transaction amount.
Kategorisasi ini dilakukan dengan mengelompokkan rata-rata besar transaksi seperti yang diperlihatkan oleh tabel berikut:
"""
plt.clf()
# Kategorisasi rata-rata besar transaksi
def f(row):
if (row['Average_Transaction_Amount'] >= 100000 and row['Average_Transaction_Amount'] <= 200000):
val ='1. 100.000 - 250.000'
elif (row['Average_Transaction_Amount'] > 250000 and row['Average_Transaction_Amount'] <= 500000):
val ='2. >250.000 - 500.000'
elif (row['Average_Transaction_Amount'] > 500000 and row['Average_Transaction_Amount'] <= 750000):
val = '3. >500.000 - 750.000'
elif (row['Average_Transaction_Amount'] > 750000 and row['Average_Transaction_Amount'] <= 1000000):
val = '4. >750.000 - 1.000.000'
elif (row['Average_Transaction_Amount'] > 1000000 and row['Average_Transaction_Amount'] <= 2500000):
val = '5. >1.000.000 - 2.500.000'
elif (row['Average_Transaction_Amount'] > 2500000 and row['Average_Transaction_Amount'] <= 5000000):
val = '6. >2.500.000 - 5.000.000'
elif (row['Average_Transaction_Amount'] > 5000000 and row['Average_Transaction_Amount'] <= 10000000):
val = '7. >5.000.000 - 10.000.000'
else:
val = '8. >10.000.000'
return val
# Tambahkan kolom baru
df['Average_Transaction_Amount_Group'] = df.apply(f, axis=1)
df_year = df.groupby(['Average_Transaction_Amount_Group'])['Customer_ID'].count()
df_year.plot(x='Average_Transaction_Amount_Group', y='Customer_ID', kind='bar',
title='Customer Distribution by Average Transaction Amount Group')
plt.xlabel('Average Transaction Amount Group')
plt.ylabel('Num of Customer')
plt.tight_layout()
#plt.savefig("averageTransaction.png", format='png')
plt.show()