Friday FED, 20, 2026

Today This Free Friday I am working on a project on YouTube a Personal Finance Tracker.

import pandas as pd
import csv
from datetime import datetime

class CSV:
    CSV_FILE = "finance_data.csv"
    COLUMS = ["date", "amount", "category", "description"]

    @classmethod
    def initializes_csv(cls):
        try:
            pd.read_csv(cls.CSV_FILE)
        except FileNotFoundError:
            df = pd.DataFrame(colums=cls.COLUMS)
            df.to_csv(cls.CSV_FILE, index=False)

    @classmethod
    def add_entry(cls, date, amount, category, description):
        new_entry = {
            "date":date,
            "amount": amount,
            "category":category,
            "description": description,
        }

        with open(cls.CSV_FILE, "a", nweline="") as csvfile:
            writer = csv.DictWriter(csvfile, fieldnames=cls.COLUMS)
            writer.writerow(new_entry)
        print("Entry added successfully")

CSV.initializes_csv()
CSV.add_entry("20-2-2026", 125.65, "Income", "Salary")
  • This part of the code is for the CSV file in the Personal Finance Tracker.
 @classmethod
    def add_entry(cls, date, amount, category, description):
        new_entry = {
            "date":date,
            "amount": amount,
            "category":category,
            "description": description,
        }

        with open(cls.CSV_FILE, "a", nweline="") as csvfile:
            writer = csv.DictWriter(csvfile, fieldnames=cls.COLUMS)
            writer.writerow(new_entry)
        print("Entry added successfully")

CSV.initializes_csv()
CSV.add_entry("20-2-2026", 125.65, "Income", "Salary")
  • This part of the code is for the new entry for the CSV file and the Dictionary.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top