1 回答

TA貢獻1780條經(jīng)驗 獲得超5個贊
我使用你的代碼作為基線,然后構(gòu)建了以下內(nèi)容:
shaped_timevalues = dict()
from datetime import datetime
fmt = '%H:%M:%S'
for i,j in time_values.items():
? ? newlist = list()
? ? sequence = [j[0]] #list with the 'linked times', with the first value already inserted
? ? for n in range(1, len(j)):
? ? ? ? time1 = datetime.strptime(j[n-1], fmt)
? ? ? ? time2 = datetime.strptime(j[n], fmt)
? ? ? ? minutes = (time2 - time1).total_seconds()/60 #how many minutes in difference
? ? ? ? if minutes == 5 or minutes == 6:
? ? ? ? ? ? sequence.append(j[n])
? ? ? ? else:
? ? ? ? ? ? newlist.append(sequence)
? ? ? ? ? ? sequence = [j[n]]
? ? if len(sequence) > 0:
? ? ? ? newlist.append(sequence)
? ? shaped_timevalues[i] = newlist
print(shaped_timevalues)
添加回答
舉報