54 lines
1.3 KiB
Python
Executable File
54 lines
1.3 KiB
Python
Executable File
def fileRW(in_f,out_f):
|
|
"""
|
|
Python fileRW assignment
|
|
Andrew Noah Woodlee
|
|
ENG 101-06
|
|
Due Date: 11-14-19
|
|
|
|
fileRW(in_f,out_f)
|
|
Input:
|
|
in_f is the input filename
|
|
out_f is the output filename
|
|
|
|
Function averages data in input file and outputs to output file
|
|
"""
|
|
|
|
import csv as c
|
|
C1=[]
|
|
C2=[]
|
|
rowdata=[C1,C2]
|
|
with open(in_f,newline='') as in_f2:
|
|
rf=c.reader(in_f2 , delimiter="*")
|
|
Header=True
|
|
for rowdata in rf:
|
|
if Header:
|
|
Head_Data=rowdata
|
|
Header=False
|
|
else:
|
|
C1.append(float(rowdata[0]))
|
|
C2.append(float(rowdata[1]))
|
|
while True:
|
|
uiDataPts=input("How many points do you want me to average: ")
|
|
try:
|
|
uiDataPts=int(uiDataPts)
|
|
if uiDataPts < 0:
|
|
print("Input must be a positve integer, try again.")
|
|
continue
|
|
break
|
|
except ValueError:
|
|
print("Input must be an integer!")
|
|
with open(out_f, 'w', newline='') as outf:
|
|
OData=c.writer(outf, delimiter=",")
|
|
OData.writerow(Head_Data)
|
|
L=len(C1)
|
|
n=int(L/uiDataPts)
|
|
for i in range(0,n):
|
|
avg1=0
|
|
avg2=0
|
|
for j in range(0,uiDataPts):
|
|
avg1+=C1[i*uiDataPts+j]
|
|
avg2+=C2[i*uiDataPts+j]
|
|
avg1/=uiDataPts
|
|
avg2/=uiDataPts
|
|
rout=[str(avg1)]+[str(avg2)]
|
|
OData.writerow(rout) |