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