Python/CSV Read Data -


my program shown below has goal of outputting statements based off 2 criteria:(year , location) once accomplished, next goal match year yearlink , location location. location , year both input statements. output should statement outputs values row. reason, receive error many values unpack. when fix error, never outputs section of program. first part of program outputting correctly. second part either giving me value error or not outputting @ all. excel sheet posted if wants better idea of talking about.excel sheet anyway tried nothing working me.

traceback (most recent call last): file "c:/users/roszkowskim/desktop/win4.py", line 134, in <module> from,to,max,min in data: valueerror: many values unpack 

-

load_gen_datafile = 'c:\users\roszkowskim\desktop\data_2016.csv' # csv file read     # read entire csv python.     # csv has columns starting year,busnum,busname,scaled_power,tla,location     data = list(csv.reader(open(load_gen_datafile)))     mydict = {}     row in data:         year,busnum,busname,scaled_power,tla,location,yearlink,from,to,max,min = row[0:12]        #if year not seen before, add dictionary     if year not in mydict:         mydict[year] = {}      busses_in_year = mydict[year]     if location not in busses_in_year:          busses_in_year[location] = []       #add bus list of busses stop @ location     busses_in_year[location].append((busnum,busname,scaled_power)) #-------------------------------------------------------------------------------    #------------------------------------------------------------------------------------------------------------------------------------- #user input statement year = raw_input("please select year of study: ") print("\n")  commands = ["millwood-buchanan", "astoria-east-corona", "bronx", "dunwoodie-north-sherman_creek",             "vernon", "greenwood-statenisland","west_49th","east_13th","staten_island","east_river",             "east_view","dunwoodie-south","corona-jamaica","astoria-east-corona-jamaica",             "astoria-west-queensbridge-vernon","astoria-west-queensbridge"] max_columns = 50  index, commands in enumerate(commands):     stars_amount = max(max_columns - len(commands), 0)     row = "# {} {}({})".format(commands, "." * stars_amount, index + 1)     print(row) location=raw_input(" \n list above show tla pockets id numbers assigned them ()\n\n please enter id #: ") print("\n") year=year location=location     if year in mydict , location in mydict[year]:       busses_in_year = mydict[year]     print("here busses @ location year , new load total: ")     print("\n")   #busnum, busname,scaled_power read excel sheet matching year , location  busnum,busname,scaled_power in busses_in_year[location]:     scaled_power= float(scaled_power)     busnum = int(busnum)     print('bus #: %d\t' % busnum ,'area station: %s\t'% busname,'new load total: %d mw\t' % scaled_power) else:         exit 

-

 row in data:     year,busnum,busname,scaled_power,tla,location,yearlink,from,to,max,min = row[0:11]      if yearlink==year , location==location:             from,to,max,min in data:                 from=int(from)                 to=int(to)                 max=float(max)                 min=float(min)                 print('from bus #: %d\t' % ,'to bus #: %d\t'% to,'vmax: %d pu\t' % max, 'vmin: %d pu\t' % min)                                                                  else:                                                                                                                    exit 

you iterating on data rows, iterate again on data from, to, max , min, had unpacked. line doesn't make sense. should work:

for row in data:     data_location, year_link, from_, to, max_value, min_value = row[5:11]     output = 'from bus #: {}\tto bus #: {}\tvmax: {} pu\tvmin: {} pu\t'     if year_link == year , data_location == location:         print(output.format(from_, to, max_value, min_value)) 

i simplified bit , changed variable names, thing have remove spurious for line.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -