I have a CSV file like this:
Header1,Header2,Header3,Header4
AA,12,ABCS,A1
BDDV,34,ABCS,BB2
ABCS,5666,gf,KK0
where a column can have only letters/words, or just numbers or both. I have multiple files like this and the columns are not necessarily the same in each. I'd like to get the counts of each element in a column that has only letters and no numbers in it.
My desired output is
Header1- [('AA', 1),('BDDV',1),('ABCS',1)] Header3- [('ABCS', 2),('gf', 1)]
Here, though both the columns have 'ABCS', I'd like to count them separately for each column.
I can get the count by hardcoding the column number like below:
import csv
import collections
count_number = collections.Counter()
with open('filename.csv') as input_file:
r = csv.reader(input_file, delimiter=',')
headers = next(r)
for row in r:
count_number[row[1]] += 1
print count_number.most_common()
but I'm confused on how to do it with respect to columns.