python - Split data day wise -


i have data files time epoch (unix time) , trying split data day/date wise in separate files. eg: data 90 days should spited 90 files. not know how start it. sometime know number days , dont know have ease trying find better way split data day/date wise. data[0] data[1] timeepoch[2] timeepoch[3]. time_1 , time_2 start time , stop time.

data:these few lines.

data_1  data_2  time_1  time_2 3436    1174    1756908 1759291 3436    3031    1756908 1759291 3436    1349    1756908 1759291 5372    937     1756913 1756983 4821    937     1756913 1756983 4376    937     1756913 1756983 2684    937     1756913 1756983 3826    896     1756961 1756971 3826    896     1756980 1756997 5372    937     1756983 1757045 4821    937     1756983 1757045 4376    937     1756983 1757045 2684    937     1756983 1757045 3826    896     1757003 1757053 4944    3715    1757009 1757491 4944    4391    1757009 1757491 2539    1431    1757014 1757337 5372    937     1757045 1757104 4821    937     1757045 1757104 4376    937     1757045 1757104 2684    937     1757045 1757104 896     606     1757053 1757064 3826    896     1757064 1757074 5045    4901    1757074 1757085 4921    4901    1757074 1757085 4901    3545    1757074 1757085 4901    3140    1757074 1757085 4901    4243    1757074 1757085 896     606     1757074 1757084 

import itertools import datetime  # extract date timestamp third item in line # (will grouping start timestamp) def key(s):     return datetime.date.fromtimestamp(int(s.split()[2]))  open('in.txt') in_f:     date, group in itertools.groupby(in_f, key=key):         # output file named "1970-01-01.txt"         open('{:%y-%m-%d}.txt'.format(date), 'w') out_f:             out_f.writelines(group) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -