2
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Sample dataset
data = {
'Satisfaction': ['Low', 'Medium', 'High', 'Low', 'Medium', 'High', 'High', 'Medium', 'Low',
'High', 'Medium', 'Low', 'High', 'Medium', 'Low', 'High', 'High', 'Medium', 'Low', 'High'],
'RepeatPurchase': ['No', 'Yes', 'Yes', 'No', 'No', 'Yes', 'Yes', 'Yes', 'No', 'Yes', 'Yes', 'No', 'Yes',
'No', 'No', 'Yes', 'Yes', 'Yes', 'No', 'Yes']
}
df = pd.DataFrame(data)
# Count plot to show satisfaction vs repeat purchase
plt.figure(figsize=(8, 5))
sns.countplot(data=df, x='Satisfaction', hue='RepeatPurchase')
plt.title('Customer Satisfaction vs Repeat Purchase')
plt.xlabel('Satisfaction Level')
plt.ylabel('Number of Customers')
plt.legend(title='Repeat Purchase')
plt.tight_layout()
plt.show()
# Stacked bar chart
cross_tab = pd.crosstab(df['Satisfaction'], df['RepeatPurchase'])
cross_tab.plot(kind='bar', stacked=True, color=['salmon', 'skyblue'], figsize=(8, 5))
plt.title('Stacked Bar Chart: Satisfaction vs Repeat Purchase')
plt.xlabel('Satisfaction Level')
plt.ylabel('Number of Customers')
plt.legend(title='Repeat Purchase')
plt.tight_layout()
plt.show()
Comments
Post a Comment