Python CSV Error: sequence expected

writer.writerow expects a sequence (a tuple or list) of values to write in a single row, with one value per column in that row. What you have given it instead is a single value. Your code really should look more like:

writer.writerow([tmp_STID, tmp_Times, tmp_T, tmp_RH])

and it looks to me like most of this code should be in a big loop, which runs once per station (and thus once per row).


dataCSV = open('ProgramCheck.csv', 'w') 
writer = csv.writer(dataCSV, dialect='excel')
writer.writerow(['Station ID', 'Time', 'Temperature' , 'Relative Humidity']) 

for line in inputData:
    tmp = line.split()

    tmp_STID = str(tmp[0])
    tmp_T = float(tmp[4]) 
    tmp_RH = float(tmp[3])
    tmp_Times = float(tmp[2])

    if tmp_T < 6.2 and tmp_RH > 60.0: 
        writer.writerow([tmp_STID, tmp_Times, tmp_T, tmp_RH])

file.close()

Leave a Comment