我无法接收下面列出的代码的正确输出。我用---------把它分开了。我的目标是从excel表中读取与年份和位置匹配的数据并打印出结果。那很有效。我的下一步是尝试打印出来 变量“from”,“to”,“maxx”,“min”仅基于位置。出于某种原因,它没有输出任何东西。我附上了我的excel表作为图片,以了解我想要做什么。还有一种方法可以将变量存储到字符串中。我正在尝试为此函数实现for循环,它只允许字符串值。直接在下面列出。它是括号“Excel Sheet SAMPLE OUTPUT
中的第三个值psspy.two_winding_chng_4(var1,var2,'1',[_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f, var3, var4,_f,_f,_f],[])
import os, sys
import csv
LOAD_GEN_DATAFILE = 'C:\Users\RoszkowskiM\Desktop\Data_2017.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 = row[0:6]
#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))
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")
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")
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)
if location in mydict:
for row in data:
location,fromm,to,digit,maxx,minn=row[6:12]
fromm_in_location = mydict[location]
if location not in fromm_in_location:
fromm_in_location=[]
fromm_in_location[location].append((fromm,to,digit,maxx,minn))
fromm_in_location=mydict[location]
for fromm,to,digit,maxx,minn in fromm_in_location[location]:
maxx= float(maxx)
minn=float(minn)
fromm = int(fromm)
to=int(to)
print('From #: %d\t' % fromm ,'To: %d\t'% to,'VMAX: %d \t' % maxx, 'VMIN: %d\t' %minn)