【发布时间】:2017-02-27 03:03:50
【问题描述】:
我有一个包含 1500 行数据的列表,看起来像
USGS \t 14211720 \t 2017-02-12 22:00 \t PST \t 117000 \t P 11.96 P
在我添加日期时间行之前,dischargelist 和 gagheightList 工作并给我 1400 行的计数,但是当我向其中添加日期时间时,我得到了
TypeError: strptime() argument 1 must be str, not list"
I am trying to pull the date, discharge and height to make two graphs
我的代码:
import csv
import datetime
dateList = []
dischargeList = []
gageheightList = []
readCSV = csv.reader(dataLines, delimiter = '\t')
for row in readCSV:
date_str = [2]
dateTIME = datetime.datetime.strptime(date_str,"%Y,%m,%d T%H:%M")
dateList.append(dateTIME)
discharge = row[4]
dischargeList.append(discharge)
gageheight = row[6]
gageheightList.append(gageheight)
#print(dateList)
#this line was just to test if the dates were making it to a list
print("we have {} items in the date list".format(len(dateList)))
print("we have {} items in thegage height list".format(len(gageheightList)))
print ("we have {} items in the discharge list".format(len(dischargeList)))
【问题讨论】:
-
date_str = [2]应该是date_str = row[2]
标签: python csv datetime graph datetime-format