python - Transforming a text file into column vectors -


i have text file break column vectors:

dtstamp ozone   ozone_8hr_avg     06/18/2015 14:00:00 0.071   0.059     06/18/2015 13:00:00 0.071   0.053    

how produce output in following format?

dtstamp = [06/18/2015 14:00:00, 06/18/2015]  ozone = [0.071, 0.071]  etc. 

import datetime  dtstamp = [] # initialize dtstamp list ozone = [] # initialize ozone list  open('file.txt', 'r') f:     next(f) # skip title line     line in f: # iterate through file         if not line: continue # skip blank lines         day, time, value, _ = line.split() # split line         dtstamp.append(datetime.datetime.strptime(' '.join((date, time)),           '%m/%d/%y %h:%m:%s') # add date         ozone.append(float(value)) # add value 

you can combine these lists zip work corresponding dates/values:

for date, value in zip(dtstamp, ozone):     print(date, value) # example 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -