📜  使用 NumPy 查找给定月份的工作日数

📅  最后修改于: 2022-05-13 01:55:36.018000             🧑  作者: Mango

使用 NumPy 查找给定月份的工作日数

在 NumPy 中,我们可以在 busday_count() 的帮助下找到给定月份的工作日数。在这个过程中,给定月份是第一个参数,下个月作为第二个参数。它将返回给定月份的工作日总数。

工作日仅限周一至周五。

示例#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'))


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'))


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'))


输出:

Number of weekdays in july 2020: 23

示例#2:我们可以用这个weekmask 计算周六的数量。

蟒蛇3

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'))

输出:

Number of saturday in november 2020: 4

示例#3:计算星期日的数目。

蟒蛇3

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'))

输出:

Number of Sunday in november 2020: 5