Created
June 17, 2020 00:34
-
-
Save dzakyputra/0e6dbdbc8b0d2bc84ceaac1b593e3692 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate the average spending for each gender | |
avg_spending = transcript[transcript['event'] == 'transaction'].merge(profile, left_on='person', right_on='id') \ | |
.groupby('gender', as_index=False)['amount'] \ | |
.mean() \ | |
.rename(columns={'amount': 'average_spending_per_transaction'}) \ | |
.sort_values('average_spending_per_transaction') | |
avg_spending['gender'] = avg_spending['gender'].map({'F': 'Female', 'M': 'Male', 'O': 'Others'}) | |
# Start the visualization process | |
avg_spending.set_index('gender').plot(kind='barh', color='#6fb08e', legend=False) | |
plt.title('Average Spending per Transaction') | |
plt.xlabel('Amount ($)') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment