import matplotlib.pyplot as plt import csv data_csv = 'data.csv' all_categories = dict() with open ('data.csv', mode='r') as csv_file: csv_reader = csv.DictReader(csv_file) line_count = 0 for row in csv_reader: if line_count == 0: line_count += 1 category = row['Category'] amount = row['Amount'] if category not in all_categories: all_categories[category] = int(amount); else: all_categories[category] += int(amount); description = row['Description'] line_count += 1 print(all_categories) def func(pct, allvals): absolute = int(pct/100.*sum(allvals.values())) return "{:.1f}%\n(Rs {:d})".format(pct, absolute) labels = all_categories.keys() sizes = all_categories.values() fig, ax = plt.subplots() ax.pie(sizes, autopct=lambda pct: func(pct, all_categories), textprops=dict(color="w")), total = sum(all_categories.values()) ax.legend(all_categories.keys(), loc="center left", bbox_to_anchor=(1, 0, 0.5, 1), title="Total: Rs {:d}".format(total)) ax.set_title("Goa Trip Expenses") plt.show()