Friday, March 13, 2026

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

 @classmethod
    def get_transactions(cls, start_date, end_date):
        df = pd.read_csv(cls.CSV_FILE)
        df["date"] = pd.to_datetime(df["date"], format=CSV.FORMAT)
        start_date = datetime.strptime(start_date, CSV.FORMAT)
        end_date = datetime.strptime(end_date, CSV.FORMAT)

        mask = (df["date"] >= start_date) & (df["date"] <= end_date)
        filtered_df = df.loc[mask]

        if filtered_df.empty:
            print('No transaction found in the given date range')

        else:
            print(f"Transactions from{start_date.strftime(CSV.FORMAT)} to {end_date.strftime(CSV.FORMAT)}")

            print(filtered_df.to_string(index=False, formatters={"date": lambda x: x.strftime(CSV.FORMAT)}))

            total_income = [filtered_df["category"] == "Income"]["amount"].sum()
            total_expense = filtered_df[filtered_df["category"] == "Expense"]["amount"].sum()
            print("\nSummary:")
            print(f"Total Income: ${total_income:.2f}")
            print(f"Total Expense: ${total_expense:.2f}")
            print(f"Net Savings: ${(total_income - total_expense):.2f}")

            return filtered_df
  • This part of the code is to Give the users all the transactions within a Date range
def main():
    while True:
        print("\n1. Add a new transaction")
        print("2. view transactions and summary within a date range")
        print("3. Exit")
        choice =input("Enter your choice (1-3):")

        if choice == "1":
            add()

        elif choice == "2":
            start_date = get_date("Enter the start date (dd-mm-yyyy): ")
            end_date = get_date("Enter the end date (dd-mm-yyyy):")
            df = CSV.get_transactions(start_date, end_date)

        elif choice == "3":
            print("Exiting...")
            break
        else:
            print("Invalid choice. Enter 1, 2, or 3.")

if__name__ == "__main__":
    main()
  • This part of the code is for the users to pick one of the choices and the input of a choice.

Leave a Comment

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

Scroll to Top