下面显示的程序的目标是根据两个条件输出语句:(Year
和Location
)完成后,我的下一个目标是将year
与{{Yearlink
匹配1}}和Location
与location
。 location
和year
都是输入语句。输出应该是一个输出该行值的语句。出于某种原因,我总是收到一个错误,有关太多的值要解压缩。如果有人想要更好地了解我所谈论的内容,我的excel表格会被发布。无论如何我尝试了一切,但没有任何东西对我有效。
Traceback (most recent call last):
File "C:/Users/RoszkowskiM/Desktop/win4.py", line 134, in <module>
for From,To,Max,Min in data:
ValueError: too many values to unpack
LOAD_GEN_DATAFILE = 'C:\Users\RoszkowskiM\Desktop\Data_2016.csv' # CSV File to Read
# read the entire CSV into Python.
# CSV has columns starting with Year,busnum,busname,scaled_power,tla,location
data = list(csv.reader(open(LOAD_GEN_DATAFILE)))
mydict = {}
for row in data:
Year,busnum,busname,scaled_power,tla,Location,Yearlink,From,To,Max,Min = row[0:12]
#If this is a year not seen before, add it to the 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 the bus to the list of busses that stop at this 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
for 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 The list above show the TLA Pockets as well as the ID numbers assigned to them ()\n\n Please enter the ID #: ")
print("\n")
Year=year
Location=location
if Year in mydict and 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")
#Busnum, busname,scaled_power read from excel sheet matching year and location
for 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
for row in data:
Year,busnum,busname,scaled_power,tla,Location,Yearlink,From,To,Max,Min = row[0:11]
if Yearlink==year and Location==location:
for From,To,Max,Min in data:
From=int(From)
To=int(To)
Max=float(Max)
Min=float(Min)
print('From Bus #: %d\t' % From ,'To Bus #: %d\t'% To,'VMAX: %d pu\t' % Max, 'VMIN: %d pu\t' % Min)
else:
exit