import pandas as pd
from dfply import *
from plotnine import *
import ssl
0. Loading Libraries
1. Data Loading
## adding below ssl line as it is giving ssl error locally in my machine
= ssl._create_unverified_context
ssl._create_default_https_context
= pd.read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2024/2024-02-13/historical_spending.csv')
historical_spending = pd.read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2024/2024-02-13/gifts_age.csv')
gifts_age = pd.read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2024/2024-02-13/gifts_gender.csv') gifts_gender
2. Plotting
2.1. Historical Spending Pattern
Spending Patterns Plot Code
= (gifts_age >>
plot1 ='Age',y='SpendingCelebrating')) +
ggplot(aes(x='#378DBD', color='white', width=0.7) +
geom_col(fill+
theme_minimal()
labs(= 'Age Group',
x = '% People Celebrating',
y = '% People Celebrating by Age Group'
title
)
)
print(plot1)
= (gifts_gender >>
plot2 ='Gender',y='SpendingCelebrating')) +
ggplot(aes(x='#378DBD', color='white', width=0.7) +
geom_col(fill+
theme_minimal()
labs(= 'Gender',
x = '% People Celebrating',
y = '% People Celebrating by Gender'
title
)
)
print(plot2)
= (historical_spending >>
plot3 ='Year', y='PercentCelebrating')) +
ggplot(aes(x='#378DBD', color='white', width=0.7) +
geom_col(fill+
theme_minimal()
labs(= "Year",
x = "% People Celebrating",
y = '% People Celebrating YonY'
title
)
)
print(plot3)
= (historical_spending >>
plot4 ='Year', y='PerPerson')) +
ggplot(aes(x='#378DBD', color='white', width=0.7) +
geom_col(fill+
theme_minimal()
labs(= "Year",
x = "Avg. Amount Spending Per Person",
y = 'Avg. Amount Spend per Person YonY'
title
))
print(plot4)
Findings:
- Spending percentage decreases as people age, which is quite intuitive. Although there is a decrease by 10 basis points as the age group increases, later, the decrease rate reduces, conveying that a significant number of happy couples stick to the tradition to keep their love life in the limelight.
- The percentage of people’s Valentine’s spending hasn’t reduced; instead, the spending has almost doubled over the years. Partly, this increase can be attributed to inflation, but overall, the spending has increased.
2.2. Historical Spending Pattern by Category
Spending Patterns by Category Plot Code
(>>
historical_spending "category", "value",
gather("Candy", "Flowers", "Jewelry", "GreetingCards", "EveningOut", "Clothing", "GiftCards"]
[>>
) ='Year', y='value', color='category')) +
ggplot(aes(x+
geom_line() +
theme_minimal()
labs(='Year',
x='Avg. Amount Spend per Person',
y='Avg. Amount Spend per Person YonY'
title+
) =guide_legend(title="")) + # Use an empty string to remove the legend title
guides(color=(0.35, 0.85))
theme(legend_position )
Findings:
- Spending on Jewelry and Clothing has increased over the years.
2.3. Spending Pattern by Category
Spending Patterns by Category Plot Code
(>>
gifts_age "category", "value",
gather("Candy", "Flowers", "Jewelry", "GreetingCards", "EveningOut", "Clothing", "GiftCards"]
[>>
) ='category', y='value', fill='Age')) +
ggplot(aes(x+
geom_col() +
theme_minimal()
labs(='Category of Spends',
x='Avg. % Spending',
y='Avg. Spending percentage across Categories'
title+
) =guide_legend(title="")) + # Use an empty string to remove the legend title
guides(fill=(0.5, 0.85))
theme(legend_position )
Findings:
- More people spend on candies, suggesting a desire to sweeten their partner’s experience.
- Gifting flowers and evening outings are notably common across younger age groups in comparison.
- Gifting jewelry, although less frequent, appears to be more common among younger age groups, implying a tendency to impress partners with costly gifts.
- In contrast, older generations celebrating Valentine’s Day seem to realize that words and moments are more meaningful than expensive items, reflected in the higher incidence of gifting greeting cards.
2.4. Spending Pattern by Gender
Spending Patterns by Gender Plot Code
(>>
gifts_gender "category", "value",
gather("Candy", "Flowers", "Jewelry", "GreetingCards", "EveningOut", "Clothing", "GiftCards"]
[>>
) ='category', y='value', fill='Gender')) +
ggplot(aes(x+
geom_col() +
theme_minimal()
labs(='Category of Spends',
x='Avg. % Spending',
y='Avg. Spending percentage across Categories'
title+
) =guide_legend(title="")) + # Use an empty string to remove the legend title
guides(fill=(0.5, 0.85))
theme(legend_position )
Findings:
- Men tend to predominantly choose flowers and jewelry as their gift categories.
- In contrast, women’s dominant categories are gift cards and greeting cards, and the margin between these two categories is noticeable.
- This sheds light on the differing expectations that men and women may have for their partners.