I created it because it was necessary to automatically acquire the number of holidays in the month when creating the data necessary for machine learning.
I saw many articles that judge weekdays (business days), but since there were few articles related to holiday judgment (acquisition of days), I decided to post it with a memorial meaning.
-JPBizDay: Library to get business days in Japan
--datetime: python standard library, provides classes for manipulating dates and times
--calendar: python standard library, handles date and time
First, install jpbizday.
When installing on colab, you need to add! Before pip.
!pip install jpbizday
Then import the required modules
import jpbizday import datetime import calendar
#Acquisition of today's year / month dt_now = datetime.datetime.now() year = dt_now.year month = dt_now.month #Get the number of days of the month days = calendar.monthrange(year, month) #Get the number of weekdays heijitu = jpbizday.month_bizdays(year, month) heijitu = len(a) #Get the number of days off holiday = days - heijitu print(holiday)
I think that it was possible to implement it fairly simply by using jpbizday. There are other ways! Isn't this implementation method better? If you have any advice, please feel free to contact us!
--How to use the calendar module
https://note.nkmk.me/python-days-weeks-of-the-month/ --How to use jpbizday