python 得到时间序列的每年、每月最后一天和第一天在序列中的位置

本文介绍了如何使用Python处理时间序列数据,以获取每年、每月的第一天和最后一天在序列中的位置,后续会针对相关问题进行详细解答并持续更新。
摘要由CSDN通过智能技术生成

2018.03.30

大概的函数是这个样子,里面提到的问题,未来一一解决。持续更新。

def getFirstLastDayMth(dateSeries):
    #dateSeries is like 2018-03-09
    #my date series is from 2017.1.1 till now 2018.03.30
    #import pandas as pd, import numpy as np FIRST
    datesList = pd.to_datetime(dateSeries).strftime("%Y%m%d")
    #it is a ndarray
    datesList = np.array([int(i) for i in datesList])
    trimmedDate = datesList * (float(1)/float(100))#already rounded, have no idea why
    #it is actually not rounded, it is just not showing on the variable explorer
    #to look at, please print
    #to get the last day of the month, divide with 100 and to get the last day of the year, divide with 10000
    trimmedDate = np.around(trimmedDate)
    lastDayofPeriod = trimmedDate[0:-1] - trimmedDate[1:]
    #if from the same month, the difference is 0, and if there is new month, the difference will be nonzero
    #the difference will not be -1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值