Skip to content

Instantly share code, notes, and snippets.

@dzakyputra
Created June 17, 2020 00:34
Show Gist options
  • Save dzakyputra/0e6dbdbc8b0d2bc84ceaac1b593e3692 to your computer and use it in GitHub Desktop.
Save dzakyputra/0e6dbdbc8b0d2bc84ceaac1b593e3692 to your computer and use it in GitHub Desktop.
# 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