In [20]:
import pandas as pd
#The next three lines read in the full index with values and ranks
#and converts the column to a list, which is easier to closely examine
#BE SURE TO CHANGE THE DIRECTORY PATH AND SPECIFY WHICH 3 MONTH PERIOD YOU'RE VERIFYING
Table = pd.read_csv('C:\Users\Ty Dickinson\Downloads\SONSevereImpacts.csv')
TotalReports = Table['SON Reports']
TotalReports = [int(x) for x in TotalReports] #converts items to integers and into a list
#This block gets user input for the individual indicator
print "How many total reports were there? ",
while True:
try:
Reports = int(raw_input()) #user input part
except ValueError:
#error raised because input could not be converted to an integer
#prints error statement, continue forces while statement to restart
print "Input must be an integer"
continue
else:
#input is good, breaks the while statement
break
#lambda is a small function in python that terminates after use
#i.e., it's the same as defining a function but is more concise
#and is good for doing arithmetic expressions
#it will find the closest associated value in the list by subtracting each
#value in the list, doing absolute value, and outputting the smallest number
#after subtraction
ClosestValue = min(TotalReports, key=lambda x:abs(x-Reports))
#Location will then be where in the TotalReports list that closest number occurs
Location = TotalReports.index(ClosestValue)
#Outputting the rank and year is as simple as taking the location of the
#closest value and going to that spot in the table columns
Year = Table.Year[Location]
ReportsRank = Table.Reports[Location]
print 'The closest value in the index is', ClosestValue, 'in', Year
print 'The associated rank is', ReportsRank
In [21]:
ReportDaysList = Table['SON Report Days'].tolist()
ReportDaysList = [int(x) for x in ReportDaysList]
print "What were the number of report days? ",
while True:
try:
ReportDays = int(raw_input())
except ValueError:
print "Input must be an integer"
continue
else:
break
ClosestValue = min(ReportDaysList, key=lambda x:abs(x-ReportDays))
Location = ReportDaysList.index(ClosestValue)
Year = Table.Year[Location] #will always be the first occurrance of an indicator
ReportDaysRank = Table.Days[Location]
print 'The closest value in the index is', ClosestValue, 'in', Year
print 'The associated rank is', ReportDaysRank
In [22]:
TornadoPath = Table['SON Tornado Track']
TornadoPath = [float(x) for x in TornadoPath]
print "What was the total tornado path length, in miles? ",
while True:
try:
TornadoTrack = float(raw_input())
except ValueError:
print "Input must be a number"
continue
else:
break
ClosestValue = min(TornadoPath, key=lambda x:abs(x-TornadoTrack))
Location = TornadoPath.index(ClosestValue)
Year = Table.Year[Location] #will always be the first occurrance of an indicator
TornadoPathRank = Table.Track[Location]
print 'The closest value in the index is', ClosestValue, 'in', Year
print 'The associated rank is', TornadoPathRank
In [23]:
Fatalities = Table.Blend
Fatalities = [float(x) for x in Fatalities]
print "What was the blend of fatalities and injuries? ",
while True:
try:
Blend = float(raw_input())
except ValueError:
print "Input must be a number"
continue
else:
break
ClosestValue = min(Fatalities, key=lambda x:abs(x-Blend))
Location = Fatalities.index(ClosestValue)
Year = Table.Year[Location] #will always be the first occurrance of an indicator
FatalitiesRank = Table.Fatalities[Location]
print 'The closest value in the index is', ClosestValue, 'in', Year
print 'The associated rank is', FatalitiesRank
In [24]:
Damages = Table.PythonAdjusted
Damages = [float(x) for x in Damages]
print "What was the total amount in damages, adjusted to 2010 levels? ",
while True:
try:
AdjustedDamages = float(raw_input())
except ValueError:
print "Input must be a number"
continue
else:
break
ClosestValue = min(Damages, key=lambda x:abs(x-AdjustedDamages))
Location = Damages.index(ClosestValue)
Year = Table.Year[Location] #will always be the first occurrance of an indicator
DamagesRank = Table.Damages[Location]
print 'The closest value in the index is', ClosestValue, 'in', Year
print 'The associated rank is', DamagesRank
In [25]:
TornadoWidthList = Table['SON Widest Tornado']
TornadoWidthList = [int(x) for x in TornadoWidthList]
print "What was the largest tornado width, in yards? ",
while True:
try:
TornadoWidth = int(raw_input())
except ValueError:
print "Input must be an integer"
continue
else:
break
ClosestValue = min(TornadoWidthList, key=lambda x:abs(x-TornadoWidth))
Location = TornadoWidthList.index(ClosestValue)
Year = Table.Year[Location] #will always be the first occurrance of an indicator
TornadoWidthRank = Table.Width[Location]
print 'The closest value in the index is', ClosestValue, 'in', Year
print 'The associated rank is', TornadoWidthRank
In [26]:
LargestHail = Table['SON Largest Hail']
LargestHail = [float(x) for x in LargestHail]
print "What was the largest hail size? ",
while True:
try:
Hail = float(raw_input())
except ValueError:
print "Input must be a number"
continue
else:
break
ClosestValue = min(LargestHail, key=lambda x:abs(x-Hail))
Location = LargestHail.index(ClosestValue)
Year = Table.Year[Location] #will always be the first occurrance of an indicator
LargestHailRank = Table.Hail[Location]
print 'The closest value in the index is', ClosestValue, 'in', Year
print 'The associated rank is', LargestHailRank
In [27]:
StrongestWind = Table['SON Strongest Wind']
StrongestWind = [int(x) for x in StrongestWind]
print "What was the strongest non-tornadic wind magnitude? ",
while True:
try:
Wind = int(raw_input())
except ValueError:
print "Input must be an integer"
continue
else:
break
ClosestValue = min(StrongestWind, key=lambda x:abs(x-Wind))
Location = StrongestWind.index(ClosestValue)
Year = Table.Year[Location] #will always be the first occurrance of an indicator
StrongestWindRank = Table.Wind[Location]
print 'The closest value in the index is', ClosestValue, 'in', Year
print 'The associated rank is', StrongestWindRank
In [28]:
OverallList = [ReportsRank, ReportDaysRank, TornadoPathRank,
FatalitiesRank, DamagesRank, TornadoWidthRank,
LargestHailRank, StrongestWindRank]
OverallSum = sum(OverallList)
IndexScore = abs(OverallSum - 240)
Sums = Table.Sum
Sums = [float(x) for x in Sums]
ClosestValue = min(Sums, key=lambda x:abs(x-OverallSum))
Location = Sums.index(ClosestValue)
Year = Table.Year[Location]
OverallRank = Table.Rank[Location]
print 'The closest value in the index is', ClosestValue, 'in', Year
print 'The associated rank is', OverallRank
print 'The sum of the indicators is', OverallSum
print 'The Index Score is', IndexScore
In [29]:
#To see how many times an indicator occurred in the index, do
#listName.count(value)
In [ ]: