2
2
import matplotlib .pyplot as plt
3
3
from datetime import datetime
4
4
5
+
5
6
def track_expenses ():
6
7
date = input ("Enter the date (YYYY-MM-DD): " )
7
8
description = input ("Enter the expense description: " )
@@ -11,20 +12,24 @@ def track_expenses():
11
12
try :
12
13
df = pd .read_csv ("expenses.csv" )
13
14
except FileNotFoundError :
14
- df = pd .DataFrame (columns = ["Date" , "Description" , "Amount" , "Category" ])
15
+ df = pd .DataFrame (
16
+ columns = ["Date" , "Description" , "Amount" , "Category" ])
15
17
16
- df = df .append ({"Date" : date , "Description" : description , "Amount" : amount , "Category" : category }, ignore_index = True )
18
+ df = df .append ({"Date" : date , "Description" : description ,
19
+ "Amount" : amount , "Category" : category }, ignore_index = True )
17
20
df .to_csv ("expenses.csv" , index = False )
18
21
19
22
print ("Expense added successfully!" )
20
23
24
+
21
25
def view_expenses ():
22
26
try :
23
27
df = pd .read_csv ("expenses.csv" )
24
28
print (df )
25
29
except FileNotFoundError :
26
30
print ("No expenses found." )
27
31
32
+
28
33
def generate_spending_report ():
29
34
try :
30
35
df = pd .read_csv ("expenses.csv" )
@@ -39,12 +44,14 @@ def generate_spending_report():
39
44
except FileNotFoundError :
40
45
print ("No expenses found." )
41
46
47
+
42
48
def set_budget ():
43
49
budget = float (input ("Enter your budget amount: " ))
44
50
with open ("budget.txt" , "w" ) as file :
45
51
file .write (str (budget ))
46
52
print ("Budget set successfully!" )
47
53
54
+
48
55
def reset_monthly_budget ():
49
56
now = datetime .now ()
50
57
first_day_of_month = now .replace (day = 1 ).strftime ("%Y-%m-%d" )
@@ -53,6 +60,7 @@ def reset_monthly_budget():
53
60
54
61
print ("Monthly budget and expenses reset successfully." )
55
62
63
+
56
64
def check_budget ():
57
65
try :
58
66
with open ("budget.txt" , "r" ) as file :
@@ -64,6 +72,7 @@ def check_budget():
64
72
except FileNotFoundError :
65
73
print ("Budget not set. Please set a budget first." )
66
74
75
+
67
76
def visualize_expense_distribution ():
68
77
try :
69
78
df = pd .read_csv ("expenses.csv" )
@@ -79,6 +88,7 @@ def visualize_expense_distribution():
79
88
except FileNotFoundError :
80
89
print ("No expenses found." )
81
90
91
+
82
92
def main ():
83
93
while True :
84
94
print ("\n Personal Finance Manager Menu:" )
0 commit comments