Need Help Modifying Code Fit Description Picture Inserting Code Question Parameters File O Q37101437

I need help modifying my code to fit the description in thepicture. I am inserting my code and the question parameters.

##File I/O Assignment

def readFile(filename):

with open(filename) as f:

#reads column name

col1,col2 = f.readline().strip().split(‘,’)

data = {col1:[],col2:[]}

for line in f.readlines():

c1,c2 = line.strip().split(‘,’)

# adds to dictionary

data[col1].append(c1)

data[col2].append(c2)

return data

def writeToFile(filename,data):

   with open(filename,’w’) as f:

columns = data.keys()

f.write(“,”.join(columns)+”n”)

s = []

for _,v in data.items():

s.append(v)

for col,avg,n in zip(*s):

f.write(“,”.join(map(str,[col,avg,n])))

f.write(“n”)

def fileRW4():

inputfile = “ExData2.csv”

outputfile = “ExData2Out.csv”

data = readFile(inputfile)

while 1:

try:

n = int(input(“Enter number of data points to average: “))

if n<1 :

print(“Enter a positive number.”)

continue

break

except:

print(“Invalid input. Give a whole number value.”)

cols = list(data.keys())

if n > len(data[cols[0]]):

n = len(data[cols[0]])

avg1 = sum(map(float ,data[cols[0]][:n]))/n

avg2 = sum(map(float, data[cols[1]][:n])) / n

val

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.