Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KeyError: '1'
#1
Hello everyone, I am receiving an error:
Error:
Traceback (most recent call last): File "C:\Users\RoszkowskiM\Desktop\win5.py", line 120, in <module> busses_in_year = mydict[Year] KeyError: '1'
I am assuming it has something to do with my dictionary. The goal of this code is to match year and data_location and it will output 3 sets of data. The data is coming from a csv sheet.

data = list(csv.reader(open(LOAD_GEN_DATAFILE)))for row in data:
    mydict = {}
    Year,busnum,busname,scaled_power,tla,data_location,empty,year_link,from_,to,digit,name2,tla_2,min_value,max_value = row[0:15]
    

    busses_in_year = mydict[Year]
    #Add the bus to the list of busses that stop at this location
    busses_in_year[data_location].append((busnum,busname,scaled_power))

    if Year in mydict and data_location in mydict[Year]:  
        busses_in_year = mydict[Year]
        print("Here are all the busses at that location for that year and the new LOAD TOTAL: ")
        print("\n")
    
    
        output='Bus #: {}\t Area Station: {}\t New Load Total: {} MW\t'
        print(output.format(busnum,busname,scaled_power))
            

    else:
        exit
Reply


Messages In This Thread
KeyError: '1' - by mikerosz94 - Aug-31-2017, 01:43 PM
RE: KeyError: '1' - by ichabod801 - Aug-31-2017, 03:08 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020