Skip to content

Instantly share code, notes, and snippets.

@ahmetaa
Last active May 26, 2021 21:02
Show Gist options
  • Save ahmetaa/ae4476e048d9edca8b4fc22622744774 to your computer and use it in GitHub Desktop.
Save ahmetaa/ae4476e048d9edca8b4fc22622744774 to your computer and use it in GitHub Desktop.
Csv counter
import csv
from collections import Counter
def load_csv(csv_file_path):
with open(csv_file_path) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
first_line_read = False
items = []
for row in csv_reader:
# Write header.
if not first_line_read:
first_line_read = True
print(f'[{row[0].strip()} : {row[1].strip()}]')
continue
# Add `no` to items list.
items.append(row[1])
# create a Counter with list.
counter = Counter(items)
# k = no , v = count. most_common() will sort the items by count and return a dictionary.
for k, v in counter.most_common():
print(f'{k} : {v}')
if __name__ == '__main__':
load_csv('/Users/ahmetafsinakin/Downloads/bütün sonuçlar - Sayfa1.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment