Question: e ) Suppose I have a new query: Qe: For every department, display the min, median, and max graduation years. Use your . txt file
e Suppose I have a new query: Qe: For every department, display the min, median, and max graduation years. Use your txt file containing denormalized data from partb to answer Qe with python instead of SQL Note that this solution should not use SQLite or SQL language. Your solution should work for any input, not just for specific department in your data.
My text file contains
'boars head', main stCSCACSC 'Computer Science',
'boars head', main stDSCDDSC 'Data Science',
'taco king', south stCSCBCSC 'Computer Science',
'taco king', south stDSCBDSC 'Data Science',
'blue sky east st 'ECONB 'ECON 'Economics',
'blue sky east st 'MATHC 'MATH 'Mathematics',
'Blake eats', north st 'ECONA 'ECON 'Economics',
'mike cheddar', west st 'MATHA 'MATH 'Mathematics',
my code so far is below, but it wont execute please advise the correct code
def computemedianvalues:
sortedvalues sorted values
n lensortedvalues
if n:
return sortedvaluesn
else:
mid n
returnsortedvaluesmid sortedvaluesmid
def rundatafiledatafile:
departmentdata
with opendatafile,r as file:
lines file.readlines
lines lines:
for line in lines:
parts line.stripsplitt
department,gradyearpartsfloatparts
if department not in departmentdata:
departmentdatadepartment
departmentdatadepartmentappendgradyear
for department, gradyears in departmentdata.items:
maxgradyearmaxgradyears
mediangradyearcomputemediangradyears
mingradyear mingradyear
printfDepartment:department
printfMax Graduation Year:maxgradyear
printfMedian Graduation Year:mediangradyear
printfMin Graduation Year:mingradyear
print
datafile 'inputfile.txt
rundatafiledatafile
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
