42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
|
def fileIO():
|
|||
|
"""
|
|||
|
by Daniel Armentrout
|
|||
|
ENG 101 – 06
|
|||
|
File I/O Practice Assignment
|
|||
|
Due: 11/12/19
|
|||
|
Function to read in data from a file and average
|
|||
|
10 data points in two columns. Call function with:
|
|||
|
fileIO()
|
|||
|
"""
|
|||
|
|
|||
|
import csv
|
|||
|
C1=[] # Clear list for Column 1 data
|
|||
|
C2=[] # Clear list for Column 2 data
|
|||
|
# Open and store data
|
|||
|
with open('ExData2.csv', newline='') as In_f:
|
|||
|
readf = csv.reader(In_f, delimiter="*")
|
|||
|
Header=True
|
|||
|
for row in readf:
|
|||
|
if Header:
|
|||
|
HData=row
|
|||
|
Header=False
|
|||
|
else:
|
|||
|
C1.append(float(row[0]))
|
|||
|
C2.append(float(row[1]))
|
|||
|
# Write out processed data
|
|||
|
with open('ExOut.csv', 'w', newline='') as Out_file:
|
|||
|
OData = csv.writer(Out_file, delimiter=",")
|
|||
|
OData.writerow(HData)
|
|||
|
L=len(C1)
|
|||
|
n=int(L/10)
|
|||
|
for i in range(0,n):
|
|||
|
ave1=0
|
|||
|
ave2=0
|
|||
|
for j in range(0,10):
|
|||
|
ave1+=C1[i*10+j]
|
|||
|
ave2+=C2[i*10+j]
|
|||
|
ave1/=10
|
|||
|
ave2/=10
|
|||
|
rout=[str(ave1)]+[str(ave2)]
|
|||
|
OData.writerow(rout)
|