How Strengthe of Coffee People Drink

Python
26Summer
data: coffee_survey.csv
Author

Xueming

Published

February 5, 2026

Heading of level 2

This is a paragraph of text

##Import the data

We Import the player dataset

import pandas as pd
df = pd.read_csv("../../../../data/coffee_survey.csv")
df.head()
Unnamed: 0 age cups where_drink purchase_other favourite favorite_specify additions additions_other sweetener ... most_paid most_willing value_cafe spent_equipment value_equipment gender education_level employment_status number_children political_affiliation
0 1 <18 years old 3 At home, At the office, At a cafe NaN Pourover NaN No - just black, Milk, dairy alternative, or c... NaN NaN ... NaN NaN NaN NaN NaN Other (please specify) Bachelor's degree Employed full-time More than 3 Democrat
1 2 >65 years old 3 At the office, At a cafe NaN Cortado NaN No - just black NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2 3 25-34 years old 1 At home, At the office, On the go NaN Regular drip coffee NaN Milk, dairy alternative, or coffee creamer, Su... NaN Granulated Sugar, Brown Sugar ... NaN NaN NaN NaN NaN Female Bachelor's degree Employed full-time NaN Democrat
3 4 18-24 years old 2 At the office NaN Iced coffee NaN Milk, dairy alternative, or coffee creamer NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
4 5 45-54 years old 2 At home, At the office, At a cafe, On the go NaN Regular drip coffee NaN No - just black NaN NaN ... $4-$6 $8-$10 No $500-$1000 Yes Male Master's degree Employed full-time 2 No affiliation

5 rows × 43 columns

##visualisation

Let’s add a picture

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import scipy.stats as stats

df.head(10)

strength_by_agegroup = df.groupby('age')['strength'].value_counts().unstack().fillna(0)

cmap = sns.color_palette(["#f7fbff", "#6baed6", "#08306b"], as_cmap=True)
plt.figure(figsize=(12, 6))
sns.heatmap(strength_by_agegroup, annot=True, fmt='.0f', cmap='viridis')
plt.title('Strengthe by Age Group')
plt.ylabel('Age Group')
plt.xlabel('Strength')
plt.tight_layout()
plt.show()

strength_by_agegroup.plot(kind='bar', stacked=True, figsize=(12,6), colormap='viridis')
plt.title('Strengthe of Coffee by Age Group')
plt.ylabel('Strengthe of Coffee')
plt.xlabel('Age Group')
plt.legend(title='How Strengthe of Coffee People Drink', bbox_to_anchor=(1.05, 1), loc='upper left')
plt.tight_layout()
plt.show()