Birthday Analysis


After having an exam on my birthday last year, I am horrified at the thought of having another surprise birthday accounting exam. This got me wondering what days of the week my birthdays will fall on, and what years I will have a weekend birthday. This is what I'll be looking for in this quick analysis.

In [2]:
import calendar as cal
import datetime as dt
import pandas as pd
In [3]:
dt.date(1998,2,9).strftime('%A')
Out[3]:
'Monday'

Apparently I was born on a Monday, which explains almost all of the variance in my dry sense of humor.

The following lines give the date and day of week that all my birthdays fall on until I can reasonably expect to live:

In [4]:
birthday = lambda year: dt.date(year, 2, 9)
In [5]:
df = pd.DataFrame({'year': range(2018, 2100)})
In [6]:
df['bday'] = pd.to_datetime(df.year.map(birthday))
In [7]:
df['dayofwk'] = df.bday.dt.strftime('%a')
In [8]:
df.head()
Out[8]:
year bday dayofwk
0 2018 2018-02-09 Fri
1 2019 2019-02-09 Sat
2 2020 2020-02-09 Sun
3 2021 2021-02-09 Tue
4 2022 2022-02-09 Wed

Huzzah! It looks like my next two birthdays will be on a weekend for my last two years of college.

A simple rule of thumb that I can see is that the day of the week my birthday falls on goes up by one each year, with the exception of leap years where it goes up by two.

FUN FACT: Leap years fall on the same years as the Summer Olympics.

The next block checks for if my birthday is on a weekend for a given year:

In [9]:
df['weekend'] = (df['dayofwk'] == 'Sat') | (df['dayofwk'] == 'Sun')
In [10]:
df.head()
Out[10]:
year bday dayofwk weekend
0 2018 2018-02-09 Fri False
1 2019 2019-02-09 Sat True
2 2020 2020-02-09 Sun True
3 2021 2021-02-09 Tue False
4 2022 2022-02-09 Wed False

Now I want to know how long I'll have to wait to have that sweet weekend birthday. I'll look for weekend epochs where the count is only increased on years where my birthday is on a weekend.

In [11]:
df['wknd_epoch'] = df.weekend.cumsum()
df.head(10)
Out[11]:
year bday dayofwk weekend wknd_epoch
0 2018 2018-02-09 Fri False 0
1 2019 2019-02-09 Sat True 1
2 2020 2020-02-09 Sun True 2
3 2021 2021-02-09 Tue False 2
4 2022 2022-02-09 Wed False 2
5 2023 2023-02-09 Thu False 2
6 2024 2024-02-09 Fri False 2
7 2025 2025-02-09 Sun True 3
8 2026 2026-02-09 Mon False 3
9 2027 2027-02-09 Tue False 3

This gives me a quick summary of the intervals I have to wait for a weekend birthday. The pattern seems to show that I get two weekend birthdays in a row followed by five that land on weekdays:

In [12]:
df[df['wknd_epoch'] > 0].groupby('wknd_epoch').year.agg(['size', 'min'])
#'size' returns wait time in years for next epoch and 'min' gives lowest 
#'wknd_epoch' value, which happens to be years with a weekend birthday.
Out[12]:
size min
wknd_epoch
1 1 2019
2 5 2020
3 5 2025
4 1 2030
5 5 2031
6 5 2036
7 1 2041
8 5 2042
9 1 2047
10 5 2048
11 5 2053
12 1 2058
13 5 2059
14 5 2064
15 1 2069
16 5 2070
17 1 2075
18 5 2076
19 5 2081
20 1 2086
21 5 2087
22 5 2092
23 1 2097
24 2 2098

It looks like 2020 will be my last weekend birthday and begin an epoch of weekday birthdays. If I live to see my 100th birthday, it seems that I'll be able to celebrate on a weekend! Until then, I guess I'll be working on life.

That concludes my short analysis of my birthdays. Feel free to let me know your thoughts!