Skip to content
Related Articles
Find the number of weekdays of a given month using NumPy
• Last Updated : 26 Nov, 2020

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
```

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up