日付オブジェクトX( "%Y、%m、%d")と日付Yのリストを持っていて、その中のすべての日付が+ date年を無視します。python3日付を反復する
Ex.:
timeDelta = 10days
X = [2017-10-10, 2014-09-31, 1999-05-10, 1992-10-18]
Y = 2019-10-05
Z = MyFunction(X, Y, delta)
MyFunction(X,Y, timeDelta):
for i in range((currentDate-500000),currentDate,10000): # last 50 years in 1 year steps
bottomBoundries.append(datetime.strptime(str(i),'%Y%m%d')-timedelta(timeDelta))
topBoundries.append(datetime.strptime(str(i),'%Y%m%d')+timedelta(timeDelta))
for i in range(0, pandas.shape[0], 1):
for j in range(0, len(bottomBoundries) , 1):
if ((pandas["MESS_DATUM"].iloc[i] > bottomBoundries[j]) & (pandas["MESS_DATUM"].iloc[i] < topBoundries[j])):
indices.append(i)
result = pandas.iloc[indices]
return result
これは時間がかかり、より効率的にする方法を知りました。
「2014-09-31」は有効な日付ではありません。また、最初の数行はPythonの正しい構文ではありません。日付を文字列として記述する必要があります。 –