CSV Example 2


employee.attendence.csv
==================
 
'date' 'emp_name' 'attendence'
'13-07-2015' 'deepak' 'p'
'13-07-2015' 'santosh' 'p'
'13-07-2015' 'sowmya' 'p'
'13-07-2015' 'sachin' 'ab'



csvtest.py
=======
import csv
import collections
with open('employee_attendence.csv','rb') as f:
    reader=csv.reader(f)
   
   
    for row in reader:
        x=row[0]
        row1=x.split(' ')
        #print row1[2]
        if row1[2]=="'p'":
            y=row1[2]
            c = collections.Counter(y)
           
            print (row1[1],c)
           
>>> import csvtest
("'deepak'", Counter({"'": 2, 'p': 1}))
("'santosh'", Counter({"'": 2, 'p': 1}))
("'sowmya'", Counter({"'": 2, 'p': 1}))

No comments:

Post a Comment