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


Groups > comp.lang.python > #104495 > unrolled thread

RE: Read and count

Started byJoaquin Alzola <Joaquin.Alzola@lebara.com>
First post2016-03-10 09:18 +0000
Last post2016-03-10 09:18 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#104495 — RE: Read and count

FromJoaquin Alzola <Joaquin.Alzola@lebara.com>
Date2016-03-10 09:18 +0000
SubjectRE: Read and count
Message-ID<mailman.120.1457602470.15725.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web