I'm trying to change a column of dates in my .csv file from month/day/year, to timestamp format.
I would like to change this...
VIX Close,Date,VIX High,VIX Low,VIX Open
18.22,1/2/2004,18.68,17.54,17.96
17.49,1/5/2004,18.49,17.44,18.45
16.73,1/6/2004,17.67,16.19,17.66
15.5,1/7/2004,16.75,15.5,16.72
to this...
VIX Close,Date,VIX High,VIX Low,VIX Open
18.22,1073023200.0,18.68,17.54,17.96
17.49,1073282400.0,18.49,17.44,18.45
16.73,1073368800.0,17.67,16.19,17.66
15.5,1073455200.0,16.75,15.5,16.72
I've tried many things, and I can get it to print out my desired reformatted date but below is one of the many ways I've tried to write it to the csv column.
What's the most pythonic way to get it to read, and immediately write the desired conversion in place without too many steps, which is where things lead for my when I'm trying to make this happen.
with open('testvix.csv', 'wb') as myFile:
reader = csv.writer(myFile, delimiter=',')
reader.writerow([(time.mktime(time.strptime(row[1], "%m/%d/%Y")))])
returns
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
TypeError: a bytes-like object is required, not 'str'
I'm sure I'm missing some kind of iterating through the csv somehow. I haven't been able to source this solution to my problem online yet