jpholiday
を使います。jpholiday.is_holiday
jpholiday.is_holiday_name
!pip install jpholiday
import pandas as pd
import jpholiday
start_date = '2022-05-01'
end_date = '2022-05-31'
start_date = pd.to_datetime(start_date)
end_date = pd.to_datetime(end_date)
df = pd.DataFrame(pd.date_range(start_date, end_date), columns=['date'])
df['is_holiday'] = df['date'].apply(jpholiday.is_holiday)
df['holiday_name'] = df['date'].apply(jpholiday.is_holiday_name)
df
date | is_holiday | holiday_name | |
---|---|---|---|
0 | 2022-05-01 | False | None |
1 | 2022-05-02 | False | None |
2 | 2022-05-03 | True | 憲法記念日 |
3 | 2022-05-04 | True | みどりの日 |
4 | 2022-05-05 | True | こどもの日 |
5 | 2022-05-06 | False | None |
6 | 2022-05-07 | False | None |
7 | 2022-05-08 | False | None |
8 | 2022-05-09 | False | None |
9 | 2022-05-10 | False | None |
10 | 2022-05-11 | False | None |
11 | 2022-05-12 | False | None |
12 | 2022-05-13 | False | None |
13 | 2022-05-14 | False | None |
14 | 2022-05-15 | False | None |
15 | 2022-05-16 | False | None |
16 | 2022-05-17 | False | None |
17 | 2022-05-18 | False | None |
18 | 2022-05-19 | False | None |
19 | 2022-05-20 | False | None |
20 | 2022-05-21 | False | None |
21 | 2022-05-22 | False | None |
22 | 2022-05-23 | False | None |
23 | 2022-05-24 | False | None |
24 | 2022-05-25 | False | None |
25 | 2022-05-26 | False | None |
26 | 2022-05-27 | False | None |
27 | 2022-05-28 | False | None |
28 | 2022-05-29 | False | None |
29 | 2022-05-30 | False | None |
30 | 2022-05-31 | False | None |