Open In App

Find the number of weekdays of a given month using NumPy

Improve
Improve
Like Article
Like
Save
Share
Report

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:

Python3




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.

Python3




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.

Python3




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


Last Updated : 26 Nov, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads