import os from collections import Counter import matplotlib.pyplot as plt # ------ For processed data ---------- categories_lookup_dict = {} sales_data_table = [] # ------ data loc ---------- DATA_FILE = "sales_data.csv" script_dir = os.path.abspath(os.path.dirname(__file__)) data_loc = os.path.join(script_dir, DATA_FILE) # ------ load data from file ---------- data_vector = [] with open(data_loc, "r") as file: lines = file.readlines() for line in lines: clean_line = line.strip() parts = clean_line.split(",") data_vector.append(parts) # ------ get categories ---------- raw_categories = [] for vector in data_vector: raw_categories.append(vector[1]) list_of_categories = list(set(raw_categories)) # ------ categories lookup ---------- id = 111 for category in list_of_categories: categories_lookup_dict[category] = id id += 1 # ------ load sale data table ---------- for vector in data_vector: date, make, price = vector[0], vector[1], vector[2] sales_data_table.append([date, make, price]) # ------ Count makes sold ---------- makes = [sale[1] for sale in sales_data_table] make_count = Counter(makes) # ------ Bar plot makes sold ---------- labels = list(make_count.keys()) values = list(make_count.values()) plt.figure(figsize=(6, 4)) cmap = plt.cm.get_cmap('tab20') colors = [cmap(i) for i in range(len(labels))] bars = plt.bar(labels, values, color=colors) for bar in bars: height = bar.get_height() plt.annotate( f'{int(height)}', xy=(bar.get_x() + bar.get_width() / 2, height), xytext=(0, 3), textcoords="offset points", ha='center', va='bottom', fontsize=9 ) plt.xticks(rotation=45, ha='right') plt.title('Makes Sold Count') plt.xlabel('Make') plt.ylabel('Count') plt.tight_layout() plt.show()