i want to put datetime into a array, is there a solution? i am newbie
import csv
from datetime import datetime
date = []
price = []
tdate = []
tprice = []
with open('TSLA.csv', 'r') as csvfile:
csvR = csv.reader(csvfile)
next(csvR) # skipping column names
for i,row in enumerate(csvR):
row_date = datetime.strptime(row[0], "%m/%d/%Y")
date.append(float(row_date))
price.append(float(row[5]))
if you want to see the error:
File "csvtest.py", line 14, in <module>
date.append(float(row_date))
TypeError: float() argument must be a string or a number, not 'datetime.datetime'
update
with open('TSLA.csv', 'r') as csvfile:
csvR = csv.reader(csvfile)
next(csvR) # skipping column names
for i,row in enumerate(csvR):
ts = time.strptime(row[0], "%m/%d/%Y")
time.mktime(ts)
date.append(float(ts))
price.append(float(row[5]))
error:
TypeError: float() argument must be a string or a number, not 'time.struct_time'