Sep-01-2017, 01:28 PM
The code shown below is outputting everything on my CSV sheet. It's not suppose to do that. Instead, the goal is to match
Desired output should be:
Year and data_location, which finally prints the information in that row. So for example if I input:Year=1data_location=1Desired output should be:
Output:Busnum:126688 busname:B New Load:125 Output:Busnum:126695 busname:m New Load:85 Output:Busnum:126696 busname:O New Load:77
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
# read the entire CSV into Python.
# CSV has columns starting with Year,busnum,busname,scaled_power,tla,location
year = raw_input("Please Select Year of Study: ")
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 #: ")
Year=year
data_location=location
data = list(csv.reader(open(LOAD_GEN_DATAFILE)))
mydict = {}
for row in data:
Year,busnum,busname,scaled_power,tla,data_location,empty,year_link,from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[0:16]
#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 data_location not in busses_in_year:
busses_in_year[data_location] = []
#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")
#Busnum, busname,scaled_power read from excel sheet matching year and location
for busnum,busname,scaled_power in busses_in_year[data_location]:
scaled_power= float(scaled_power)
busnum = int(busnum)
output='Bus #: {}\t Area Station: {}\t New Load Total: {} MW\t'
print(output.format(busnum,busname,scaled_power))
else:
exit
os.remove(LOAD_GEN_DATAFILE)
