Advertisement
IskandarIts

hw2

Feb 7th, 2021
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. def plot_pivot_table(pivot_table):
  2. plt.figure(figsize=(14, 11))
  3. sns.heatmap(pivot_table, cmap="YlGnBu", annot=True,
  4. fmt='.3g', annot_kws={"size": 14, "fontsize": 14})
  5. plt.xticks(fontsize=15)
  6. plt.yticks(rotation=0, fontsize=15)
  7. plt.xlabel('Bucket', size=18)
  8. plt.ylabel('Hour', fontsize=18)
  9. plt.title('Gender analysis per bucket and hour', fontsize=20)
  10. plt.show()
  11.  
  12. negative = transactions[transactions.amount<0].amount
  13.  
  14. transactions['amount_bucket'] = pd.cut(negative, 5, labels=['Very High', 'High', 'Middle', 'Low', 'Very Low'])
  15. transactions
  16.  
  17. transactions['amount_bucket'] = transactions['amount_bucket'].cat.add_categories('Income').fillna('Income')
  18.  
  19. transactions['tr_hour'] = transactions['tr_datetime'].apply(lambda x: x.split()[1].split(':')[0])
  20.  
  21. tp = transactions.pivot_table(['gender'], index=['tr_hour'], columns=['amount_bucket'])
  22.  
  23. plot_pivot_table(tp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement