Read and count
Joaquin Alzola
Joaquin.Alzola at lebara.com
Thu Mar 10 04:18:28 EST 2016
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 at python.org] On Behalf Of Val Krem via Python-list
Sent: 09 March 2016 21:31
To: python-list at 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.
More information about the Python-list
mailing list