Dec-31-2018, 04:32 PM
Hello all, trying to convert a VBA/Excel process to use python and am stuck, I think, on the syntax. Any help is appreciated!
I have a .csv file that contains about 70k rows and 23 columns (row count and content will change, but columns are fixed). I'd like to have python read the file (which is working okay), then generate a list of unique values in column 13, and a count of each of those unique items where column 8 has a specific variable.
For example, I want the count of colors from column 13 with "ABC" in column 8
Col 8 Col 13
ABC Yellow
ABC Red
DEF Yellow
ABC Green
ABC Red
Ideally, the output should show something like this:
Yellow, 1
Red, 2
Green, 1
I'm able to read the file and find the items with the value I want in column 8, but not sure how to make the unique list and get the counts
I have a .csv file that contains about 70k rows and 23 columns (row count and content will change, but columns are fixed). I'd like to have python read the file (which is working okay), then generate a list of unique values in column 13, and a count of each of those unique items where column 8 has a specific variable.
For example, I want the count of colors from column 13 with "ABC" in column 8
Col 8 Col 13
ABC Yellow
ABC Red
DEF Yellow
ABC Green
ABC Red
Ideally, the output should show something like this:
Yellow, 1
Red, 2
Green, 1
I'm able to read the file and find the items with the value I want in column 8, but not sure how to make the unique list and get the counts
import csv with open('C:\\Users\\myfile.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=',') for row in readCSV: if row[8] == 'ABC': print(row[13],row[8])Thank you for any guidance!