file I/O and arithmetic calculation

K

Keira Wilson

Dear all,

I would appreciate if someone could write a simple python code for the
purpose below:

I have five text files each of 10 columns by 10 rows as follows:

file_one = 'C:/test/1.txt'
file_two = 'C:/test/2.txt' . . .
file_five = 'C:/test/5.txt'

I want to calculate the mean of first row (10 elements) for each file (5
files), if mean of first column (10 elements) of each file (5 files) is 50.

Thank you in advance.

Keira
 
D

Denis McMahon

I would appreciate if someone could write a simple python code for the
purpose below:

Didn't have your data, so couldn't verify it completely, but try this:

import re
def v(s):
l=len(s)
t=0.
for i in range(l):
t=t+(abs(ord(s))*1.)
return t/(l*1.)
for n in range(5):
m="c:/test/"+str(n+1)+".txt"
f=open(m,"r")
d=[]
t=0.
for l in range(10):
d=d+[re.findall(r"[0-9.eE+-]+",f.readline())]
t=t+v(d[l][0])
f.close()
c=t/10.
if c==50.:
t=0.
for u in range(10):
t=t+v(d[0])
r=t/10.
print "%s C1: %f R1: %f"%(m,c,r)
 
C

Carlos Nepomuceno

----------------------------------------
From: (e-mail address removed) [...]

import re
def v(s):
l=len(s)
t=0.
for i in range(l):
t=t+(abs(ord(s))*1.)
return t/(l*1.)
for n in range(5):
m="c:/test/"+str(n+1)+".txt"
f=open(m,"r")
d=[]
t=0.
for l in range(10):
d=d+[re.findall(r"[0-9.eE+-]+",f.readline())]
t=t+v(d[l][0])
f.close()
c=t/10.
if c==50.:
t=0.
for u in range(10):
t=t+v(d[0])
r=t/10.
print "%s C1: %f R1: %f"%(m,c,r)


Can you send it again without tabs?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top