I have a csv file with 'n' columns. I need to get the rowcount of each column using the column name and give out a dictionary of the following format:
csv_dict= {col_a:10,col_b:20,col_c:30}
where 10,20 and 30 are the row count of col a, b and c respectively. I obtained a list of columns using fieldnames option of Dictreader. Now i need the row count of every column in my list.
This is what I tried:
for row in csv.DictReader(filename):
col_count= sum(1 for row['col_a'] in re)+1
This just gets the row count of column a. How to get the row counts of all the columns in my list and put them in a dictionary in the above mentioned format? Any help appreciated. Thanks and regards.