python 每周第一天和最后一天

本文将介绍如何使用Python编程语言有效地获取一周的第一天和最后一天,这对于时间序列分析和日程管理非常有用。内容包括相关的时间库函数讲解及示例代码演示。
摘要由CSDN通过智能技术生成

后续详细。

def getFirstLastDayListWk(dateSeries):
    weekNum = pd.to_datetime(dateSeries).strftime("%W")
    weekNum = weekNum.astype(int)
    weekNum0 = np.argwhere(weekNum == 0)
    #assuming the first date is not 0 week, otherwise, it needs more
    for i in range(len(weekNum0)):
        weekNum[list(weekNum).index(0)] = weekNum[list(weekNum).index(0)-1]  
        #index(0)returns the location of the first 0 it appears
    #assuming that the #no assuming change them
    lastDayofPeriod = weekNum[0:-1] - weekNum[1:]
    # 0 -1 0r 51, 51 is the difference of the 52 and 1
    #nonono, it can give the result of -2, where there are holidays such as the 
    #spring festival and the national day. but they have one charactersitics in common
    #they are positive, not always 51, they can be 52, such as the year 2018
    lastDayList = np.argwhere(lastDayofPeriod!=0)
    #lastDayofPeriod[np.where((lastDayofPer
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值