我从csv文件中提取数据,并从每行数据中打印出三个字母的国家/地区代码。如何让python从输出的数据中识别每个唯一国家代码的出现次数?以下是我打印国家/地区代码的内容。
import csv
with open('2017CountryData.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
countries = row[1]
print(countries)
答案 0 :(得分:0)
import csv
with open('2017CountryData.csv') as csvfile:
countries = []
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
if row[1] not in countries:
countries.append(row[1])
print(Counter(countries))