📌  相关文章
📜  如何使用 NumPy 查找给定月份的第一个星期一?

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

如何使用 NumPy 查找给定月份的第一个星期一?

要找到给定月份的第一个星期一,我们将使用numpy模块,即numpy模块中的numpy.busday_offset()方法。

下面是一些使用numpy.busday_offset()方法获取一个月的第一个星期一的程序:

示例#1:

在此示例中,我们将找到 2017 年 5 月的第一个星期一。

Python3
# import module
import numpy
  
# input year and month
yearMonth = '2017-05'
  
# getting date of first monday
date = numpy.busday_offset(yearMonth, 0, 
                           roll='forward', 
                           weekmask='Mon')
  
# display date
print(date)


Python3
# import module
import numpy
  
# input year and month
yearMonth = '2001-02'
  
# getting date of first monday
date = numpy.busday_offset(yearMonth, 0,
                           roll='forward',
                           weekmask='Mon')
  
# display date
print(date)


Python3
# import module
import numpy
  
# input year and month
yearMonth = '2020-11'
  
# getting date of first monday
date = numpy.busday_offset(yearMonth, 0,
                           roll='forward',
                           weekmask='Mon')
  
# display date
print(date)


输出:

2017-05-01

示例#2:

在这里,我们将找到 2001 年 2 月的第一个星期一。

蟒蛇3

# import module
import numpy
  
# input year and month
yearMonth = '2001-02'
  
# getting date of first monday
date = numpy.busday_offset(yearMonth, 0,
                           roll='forward',
                           weekmask='Mon')
  
# display date
print(date)

输出:

2001-02-05

示例#3:

在这里,我们将找到 2020 年 11 月的第一个星期一。

蟒蛇3

# import module
import numpy
  
# input year and month
yearMonth = '2020-11'
  
# getting date of first monday
date = numpy.busday_offset(yearMonth, 0,
                           roll='forward',
                           weekmask='Mon')
  
# display date
print(date)

输出:

2001-11-02