Open In App

Find the number of weekdays of a given month using NumPy

In NumPy we can find the number of weekdays in a given month with the help of busday_count() In this pass the given month is the first parameter and next month as the second parameter. It will return the total number of weekdays in a given month.

Syntax:



numpy.busday_count(begindates, enddates, weekmask)

Parameters:



begindates: The array of the first dates for counting.

enddates: The array of the end dates for counting, which are excluded from the count themselves.

weekmask: Select the days

Weekdays are from Monday to Friday only.

Example #1:




import numpy as np
  
# Number of weekdays in july 2020
print("Number of weekdays in july 2020:",
      np.busday_count('2020-07', '2020-08'))

Output:

Number of weekdays in july 2020: 23

Example #2: We can count the number of Sat with this weekmask.




import numpy as np
  
# Number of weekdays in August 2020
print("Number of saturday in november 2020:",
      np.busday_count('2020-11', '2020-12',
                      weekmask='Sat'))

Output:

Number of saturday in november 2020: 4

 Example #3: Count the number of Sunday.




import numpy as np
  
# Number of weekdays in August 2020
print("Number of Sunday in november 2020:",
      np.busday_count('2020-11', '2020-12',
                      weekmask='Sun'))

Output:

Number of Sunday in november 2020: 5

Article Tags :