简体   繁体   中英

python: print 5 minute interval for a given date

I have input list which consists of event_dates

event_date
-----------
2020-05-21 01:00:45.783000
2020-05-22 01:04:25.549000
2020-05-22 01:07:27.543000
2020-05-22 01:09:57.472000
2020-05-22 01:10:57.472000
2020-05-22 01:13:00.627000
2020-05-22 01:15:00.645000
2020-05-22 01:18:23.830000
2020-05-22 01:20:24.423000
2020-05-22 01:22:39.490000

i need five_minute_intervals value for each event_date

if minutes between
[00-04] ==> 05
[05-09] ==> 10
[10-14] ==> 15
[15-19] ==> 20
[20-24] ==> 25
      :
      :

i am looking for output like below

event_date                       minute       five_minute_intervals
--------------------------------------------------------------
2020-05-21 01:00:45.783000          00           05
2020-05-22 01:04:25.549000          04           05
2020-05-22 01:07:27.543000          07           10
2020-05-22 01:09:57.472000          09           10
2020-05-22 01:10:57.472000          10           15
2020-05-22 01:13:00.627000          13           15
2020-05-22 01:15:00.645000          15           20
2020-05-22 01:18:23.830000          18           20
2020-05-22 01:20:24.423000          20           25
2020-05-22 01:22:39.490000          22           25

Can anyone suggest a solution in python?

def get_result(date):
var = 1
if (int(date.minute / 5)) == (date.minute / 5):
var = 0
print(date, date.minute, ((int(date.minute / 5) + var) * 5))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM