Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #104495

RE: Read and count

From Joaquin Alzola <Joaquin.Alzola@lebara.com>
Newsgroups comp.lang.python
Subject RE: Read and count
Date 2016-03-10 09:18 +0000
Message-ID <mailman.120.1457602470.15725.python-list@python.org> (permalink)
References <2095750566.7009618.1457559033672.JavaMail.yahoo.ref@mail.yahoo.com> <2095750566.7009618.1457559033672.JavaMail.yahoo@mail.yahoo.com>

Show all headers | View raw


Try to do a .split(' ') and then add field 0 and 1 to an list.

For open the file you can do it easier:

with open(file) as f:
for line in f:
print('line')

-----Original Message-----
From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com@python.org] On Behalf Of Val Krem via Python-list
Sent: 09 March 2016 21:31
To: python-list@python.org
Subject: Read and count

Hi all,

I am a new learner about python (moving from R to python) and trying  read and count the number of observation  by year for each city.


The data set look like
city year  x

XC1 2001  10
XC1   2001  20
XC1   2002   20
XC1   2002   10
XC1 2002   10

Yv2 2001   10
Yv2 2002   20
Yv2 2002   20
Yv2 2002   10
Yv2 2002   10

out put will be

city
xc1  2001  2
xc1   2002  3
yv1  2001  1
yv2  2002  3


Below is my starting code
count=0
fo=open("dat", "r+")
str = fo.read();
print "Read String is : ", str

fo.close()


Many thanks
--
https://mail.python.org/mailman/listinfo/python-list
This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

RE: Read and count Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-03-10 09:18 +0000

csiph-web