Using Python how to get number of occurance of a string in 'n' number of columns from a .csv file

87 views Asked by At
I am new to python and my test report is a .csv file like this :

Stream play pause seek
1.mp3 PASS FAIL FAIL
1.ac3 PASS PASS FAIL
2.mp3 FAIL PASS PASS
3.mp3 PASS PASS FAIL
4.mp4 FAIL FAIL PASS

I want to get total number of "PASS" from all the columns.

Reslult should be like : Total tests : 15 No. of pass : 8 No of Fail : 7

Please suggest how to extract the string "PASS" from the columns "play" "pause" and "seek".

1

There are 1 answers

0
Shruthi Chandra On

I could do it using pandas module. Here is the code below:

import pandas as pd
pdread = pd.read_csv(csv_file)
for i in xrange(1,3,1):
    count = collections.Counter(pdread['play'])
    for (k,v) in collections.Counter(count).iteritems():
        #K here is either "PASS" or "FAIL"
        print k
        #v is count
        print v