首先我要说的是,我是Python的初学者。
我尝试做的是从相对较大的CSV文件(大约33k数据点)读取数据。数据包括从10月到今天每3分钟3个不同站点的各种读数。我想要做的是过滤数据,所以我只得到从下午5点(17点)到晚上7点(19点)(每天)的结果,并只分析那组数据。
到目前为止我的代码是:
import csv
#Initialize list of different columns from my CSV file
date = []
time = []
Value1 = []
Value2 = []
Value3 = []
with open('MW_DATA_DIV.csv' , 'r') as csvfile:
test = csv.reader(csvfile, delimiter= ',')
for row in test:
date.append(row[0])
time.append(row[1])
Value1.append((row[2]))
Value2.append((row[3]))
Value3.append((row[4]))
#print to see if all the data was acquired as desired
'''
print (len(time))
print (len(Value1))
print (len(Value2))
print (len(Value3))
print (len(date))
'''
#Sets a counter to run 1 by 1 thru the list "time"
for counter in time:
hours = counter[0:2] #Get first 2 digits (i.e. 17, which are the hours i want to take data from)
#print (hours)
#print (type(hours))
if hours is "15" :
print("[add code HERE]")
elif hours is "16" :
print("[also add code hereee]")
elif hours is "17":
print("Also Add code HERE")
我遇到的问题是我没有收到任何消息(在此处添加代码)所以它就像没有执行if语句一样。我已经检查过,数据是一个字符串。每当我打印(小时)时,我得到每小时的读数(即:0:05,0:10,0:15,......,23:55,......等)就像我想要的那样...
我不确定我在if语句中遇到的问题是它没有执行它们。欢迎任何帮助/建议/问题!!