Question 4:Types of spenders
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
# Calculate the average Annual Income and Spending Score for each Genre
genre_metrics = df.groupby('Genre')[['Annual_Income_(k$)', 'Spending_Score']].mean().reset_index()
# Melt the DataFrame to a long format for plotting
genre_metrics_melted = genre_metrics.melt(id_vars='Genre', var_name='Metric', value_name='Average_Value')
plt.figure(figsize=(10, 6))
sns.barplot(x='Genre', y='Average_Value', hue='Metric', data=genre_metrics_melted, palette='tab10')
plt.title('Average Annual Income and Spending Score by Genre')
plt.xlabel('Genre')
plt.ylabel('Average Value')
plt.legend(title='Metric')
plt.tight_layout()
plt.show()
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
plt.figure(figsize=(8, 6)) # Reduced figure size
sns.scatterplot(x='Annual_Income_(k$)', y='Spending_Score', hue='Age', sizes=(10, 200), data=df, palette='viridis', alpha=0.7) # Adjusted point sizes
plt.title('Spending Score vs. Annual Income, Colored by Age')
plt.xlabel('Annual Income (k$)')
plt.ylabel('Spending Score (1-100)')
plt.legend(title='Age', loc='best') # Simplified legend placement
plt.grid(True, linestyle='--', alpha=0.6)
plt.tight_layout()
plt.show()