I am trying to read in two columns from a .txt file and reformat them. The first column is the date, with the format: %Y-%m-%d %H:%M:%S. The second column is a precipitation value, which I need to manipulate. Ultimately, I will need to make another tab delimited .txt file with a column containing the day, a column containing the hour, a column containing the minute, and a column containing the precipitation*0.2. My code is below:
#read in file
def readfiles(file_list):
data = []
for fname in file_list:
data.append(
np.genfromtxt(fname,
usecols=(0,5),
comments='#', # skip comment lines
delimiter='\t',
dtype="|S", autostrip=True).T)
return data
data = readfiles(['soundTransit1_remote_rawMeasurements_15m.txt'])
np.set_printoptions(threshold=np.nan)
#create array containing desired precipitation values
precip = np.array(data, dtype='|S4')[:,1]
precip = precip.astype(np.float)
precip_mm = precip * 0.2
#strip date and time
for i,d in enumerate(data):
x = [dt.datetime.strptime(date,'%Y-%m-%d %H:%M:%S') for date in d[0]]
I've gotten this far, but the variable 'x' looks like this when printed:
[datetime.datetime(2015, 7, 11, 13, 30), datetime.datetime(2015, 7, 11, 13, 45), datetime.datetime(2015, 7, 11, 14, 0),
I'm not sure how to use this output and create the .txt file that I need. I also may be completely overcomplicating this, so I would be open to suggestions on how to restart the whole process from scratch.