Discover the utility of Python counters—a part of the collections module that simplifies frequency counting and element tracking. Learn how counters enhance data analysis and manipulation in your Python programming endeavors.



from collections import Counter
import csv
counter = Counter()
with open("/Users/npblue/PycharmProjects/data/credit.csv", 'r') as file:
  csvreader = csv.reader(file, delimiter=',')
  count=0
  for row in csvreader:
      if count==0:
          count += 1
      else:
          counter+=Counter({float(row[7])})


print(counter)
def getMedian(lst):
    sorted_lst = sorted(lst)
    n = len(sorted_lst)
    if n % 2 == 0:
        middle1 = sorted_lst[n // 2 - 1]
        middle2 = sorted_lst[n // 2]
        median = (middle1 + middle2) / 2
    else:
        median = sorted_lst[n // 2]
    return median
print("Type  :",type(counter))

print("min value :",min(counter))

print("max value :",max(counter))

print("mean value :",sum(counter)//len(counter))

print("median value :",getMedian(counter))