Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45751
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <carlosnepomuceno@outlook.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.028 |
| X-Spam-Evidence | '*H*': 0.94; '*S*': 0.00; 'skip:[ 20': 0.04; 'column': 0.07; 'subject:file': 0.07; 'filenames': 0.09; 'rows': 0.09; 'python': 0.11; '###': 0.16; '6th': 0.16; 'assumptions': 0.16; 'columns': 0.16; 'csv': 0.16; 'files)': 0.16; 'need:': 0.16; 'received:65.55.116.7': 0.16; 'separated': 0.16; 'subject:arithmetic': 0.16; 'all,': 0.19; 'advance.': 0.19; "skip:' 30": 0.19; 'thu,': 0.19; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'received:65.55.116': 0.24; 'skip:{ 20': 0.24; 'subject:/': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'url:mailman': 0.30; 'code': 0.31; 'lines': 0.31; "skip:' 10": 0.31; 'file': 0.32; 'text': 0.33; 'url:python': 0.33; 'date:': 0.34; 'could': 0.34; 'url:listinfo': 0.36; 'url:org': 0.36; 'requirements': 0.37; 'email addr:python.org': 0.37; 'skip:o 20': 0.38; 'thank': 0.38; 'follows:': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'skip:_ 30': 0.39; 'subject:': 0.39; 'to:addr:python.org': 0.39; '8bit%:6': 0.40; 'url:mail': 0.40; '5th': 0.60; 'simple': 0.61; 'first': 0.61; 'email addr:gmail.com': 0.63; 'such': 0.63; 'dear': 0.65; 'email name :python-list': 0.65; 'below:': 0.68; '1st': 0.74; 'as:': 0.81; '(10': 0.84; '+0900': 0.84; '8bit%:24': 0.84; '8bit%:18': 0.93; 'average': 0.93; '2013': 0.98 |
| X-TMN | [VfL9gqDvWdyZI1SkQ6Sa38aMH3oIf4Fe] |
| X-Originating-Email | [carlosnepomuceno@outlook.com] |
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
| To | "python-list@python.org" <python-list@python.org> |
| Subject | RE: file I/O and arithmetic calculation |
| Date | Thu, 23 May 2013 00:05:15 +0300 |
| Importance | Normal |
| In-Reply-To | <CAK9meDsND9501=2ydmCAFi4s6+fw+rTrDGJA2qpEyXKoae6Axw@mail.gmail.com> |
| References | <CAK9meDsND9501=2ydmCAFi4s6+fw+rTrDGJA2qpEyXKoae6Axw@mail.gmail.com> |
| Content-Type | text/plain; charset="iso-8859-1" |
| Content-Transfer-Encoding | quoted-printable |
| MIME-Version | 1.0 |
| X-OriginalArrivalTime | 22 May 2013 21:05:15.0995 (UTC) FILETIME=[0EE04AB0:01CE5730] |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1975.1369256725.3114.python-list@python.org> (permalink) |
| Lines | 62 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1369256725 news.xs4all.nl 15882 [2001:888:2000:d::a6]:46056 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:45751 |
Show key headers only | View raw
Funny! I made a lot of assumptions regarding your requirements specification. Let me know if it isn't what you need:
### 1strow_average.py ###
#Assuming you have CSV (comma separated values) files such as:
#1.txt = '0,1,2,3,4,5,6,7,8,9\n' \
# '10,11,12,13,14,15,16,17,18,19\n' \
# '20,21,22,23,24,25,26,27,28,29\n' ...
#
# Usage: contents[file][row][column]
# contents[0] : file '1.txt'
# contents[1][2] : 3rd row of file '2.txt'
# contents[3][4][5] : 6th column of 5th row of file '4.txt'
# len(contents) : quantity of files
# len(contents[4]) : quantity of lines in file '5.txt'
# len(contents[4][0]: quantity of values in the 1st line of file '5.txt'
filenames = ['1.txt', '2.txt', '3.txt', '4.txt', '5.txt']
contents = [[[int(z) for z in y.split(',')] for y in open(x).read().split()] for x in filenames]
s1c = [sum([r[0] for r in f]) for f in contents]
a1r = [sum(f[0])/float(len(f[0])) for f in contents]
print '\n'.join([x for x in ['File "{}" has 1st row average = {:.2f}'.format(n,a1r[i]) if s1c[i]==50 else '' for i,n in enumerate(filenames)] if x])
________________________________
> From: wilkeira@gmail.com
> Date: Thu, 23 May 2013 01:13:19 +0900
> Subject: file I/O and arithmetic calculation
> To: python-list@python.org
>
>
> 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
>
>
> -- http://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
RE: file I/O and arithmetic calculation Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-23 00:05 +0300
csiph-web