Skip to content

Commit 338bc38

Browse files
Merge pull request #2582 from andoriyaprashant/branch25
Personal Finance Manager Script Added
2 parents cb5ad9e + eb311f8 commit 338bc38

File tree

3 files changed

+245
-0
lines changed

3 files changed

+245
-0
lines changed

Personal Finance Manager/README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Personal Finance Manager
2+
3+
The Personal Finance Manager is a Python script that helps users manage their personal finances by tracking expenses, setting budgets, and generating spending reports. The script utilizes the Pandas library for data handling and Matplotlib for data visualization.
4+
5+
## Features
6+
7+
1. **Track Expenses:** Allows users to add expenses with details such as date, description, amount, and category.
8+
9+
2. **View Expenses:** Displays a table of all tracked expenses.
10+
11+
3. **Generate Spending Report:** Presents a pie chart visualization of spending based on expense descriptions.
12+
13+
4. **Set Budget:** Enables users to set their monthly budget.
14+
15+
5. **Reset Monthly Budget and Expenses:** Resets the budget and expenses at the beginning of each month.
16+
17+
6. **Check Remaining Budget:** Displays the remaining budget after deducting total expenses from the set budget.
18+
19+
7. **Visualize Expense Distribution:** Shows a bar chart of the total expenses per expense category.
20+
21+
## How to Use
22+
23+
1. Ensure you have Python installed on your machine.
24+
25+
2. Install required libraries using pip:
26+
27+
```bash
28+
pip install pandas matplotlib
29+
```
30+
31+
3. Run the personal_finance_manager.py script:
32+
33+
```bash
34+
python personal_finance_manager.py
35+
```
36+
37+
4. The script will display the main menu. Here's an example of how you can use the different features of the Personal Finance Manager:
38+
39+
```bash
40+
Personal Finance Manager Menu:
41+
1. Track Expenses
42+
2. View Expenses
43+
3. Generate Spending Report
44+
4. Set Budget
45+
5. Reset Monthly Budget and Expenses
46+
6. Check Remaining Budget
47+
7. Visualize Expense Distribution
48+
8. Exit
49+
50+
Enter your choice (1-8):
51+
```
52+
53+
- Choose option 4 to set your monthly budget:
54+
55+
```bash
56+
Enter your choice (1-8): 4
57+
Enter your budget amount: 1000
58+
Budget set successfully!
59+
```
60+
- Choose option 1 to track expenses:
61+
62+
```bash
63+
Enter your choice (1-8): 1
64+
Enter the date (YYYY-MM-DD): 2023-07-15
65+
Enter the expense description: Groceries
66+
Enter the expense amount: 50.00
67+
Enter the expense category: Food
68+
Expense added successfully!
69+
70+
Enter your choice (1-8): 1
71+
Enter the date (YYYY-MM-DD): 2023-07-16
72+
Enter the expense description: Movie ticket
73+
Enter the expense amount: 20.00
74+
Enter the expense category: Entertainment
75+
Expense added successfully!
76+
77+
Enter your choice (1-8): 1
78+
Enter the date (YYYY-MM-DD): 2023-07-18
79+
Enter the expense description: Gasoline
80+
Enter the expense amount: 40.00
81+
Enter the expense category: Transportation
82+
Expense added successfully!
83+
```
84+
85+
- View the recorded expenses:
86+
87+
```bash
88+
Enter your choice (1-8): 2
89+
Date Description Amount Category
90+
0 2023-07-15 Groceries 50.0 Food
91+
1 2023-07-16 Movie ticket 20.0 Entertainment
92+
2 2023-07-18 Gasoline 40.0 Transportation
93+
```
94+
95+
- Generate a spending report:
96+
97+
```bash
98+
Enter your choice (1-8): 3
99+
Total Spending: $ 110.0
100+
```
101+
102+
A pie chart will be displayed showing the spending distribution across different expense descriptions.
103+
104+
- Check the remaining budget:
105+
106+
```bash
107+
Enter your choice (1-8): 6
108+
Remaining Budget: $ 890.0
109+
```
110+
111+
- Visualize expense distribution by category:
112+
113+
```bash
114+
Enter your choice (1-8): 7
115+
```
116+
117+
A bar chart will be displayed showing the total expenses for each expense category.
118+
119+
- You can continue using other options or choose option 8 to exit the Personal Finance Manager.
120+
121+
5. The script stores expenses in the expenses.csv file and the budget in budget.txt file in the same directory as the script.
122+
123+
## Contributing
124+
125+
Contributions to the Personal Finance Manager script are welcome! If you have any suggestions, bug reports, or feature requests, please feel free to open an issue or submit a pull request.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import pandas as pd
2+
import matplotlib.pyplot as plt
3+
from datetime import datetime
4+
5+
def track_expenses():
6+
date = input("Enter the date (YYYY-MM-DD): ")
7+
description = input("Enter the expense description: ")
8+
amount = float(input("Enter the expense amount: "))
9+
category = input("Enter the expense category: ")
10+
11+
try:
12+
df = pd.read_csv("expenses.csv")
13+
except FileNotFoundError:
14+
df = pd.DataFrame(columns=["Date", "Description", "Amount", "Category"])
15+
16+
df = df.append({"Date": date, "Description": description, "Amount": amount, "Category": category}, ignore_index=True)
17+
df.to_csv("expenses.csv", index=False)
18+
19+
print("Expense added successfully!")
20+
21+
def view_expenses():
22+
try:
23+
df = pd.read_csv("expenses.csv")
24+
print(df)
25+
except FileNotFoundError:
26+
print("No expenses found.")
27+
28+
def generate_spending_report():
29+
try:
30+
df = pd.read_csv("expenses.csv")
31+
total_spending = df["Amount"].sum()
32+
33+
plt.figure(figsize=(8, 6))
34+
plt.pie(df["Amount"], labels=df["Description"], autopct="%1.1f%%")
35+
plt.title("Spending Report")
36+
plt.show()
37+
38+
print("Total Spending: $", total_spending)
39+
except FileNotFoundError:
40+
print("No expenses found.")
41+
42+
def set_budget():
43+
budget = float(input("Enter your budget amount: "))
44+
with open("budget.txt", "w") as file:
45+
file.write(str(budget))
46+
print("Budget set successfully!")
47+
48+
def reset_monthly_budget():
49+
now = datetime.now()
50+
first_day_of_month = now.replace(day=1).strftime("%Y-%m-%d")
51+
df = pd.DataFrame(columns=["Date", "Description", "Amount", "Category"])
52+
df.to_csv("expenses.csv", index=False)
53+
54+
print("Monthly budget and expenses reset successfully.")
55+
56+
def check_budget():
57+
try:
58+
with open("budget.txt", "r") as file:
59+
budget = float(file.read())
60+
df = pd.read_csv("expenses.csv")
61+
total_spending = df["Amount"].sum()
62+
remaining_budget = budget - total_spending
63+
print("Remaining Budget: $", remaining_budget)
64+
except FileNotFoundError:
65+
print("Budget not set. Please set a budget first.")
66+
67+
def visualize_expense_distribution():
68+
try:
69+
df = pd.read_csv("expenses.csv")
70+
category_group = df.groupby("Category")["Amount"].sum()
71+
72+
plt.figure(figsize=(10, 6))
73+
plt.bar(category_group.index, category_group.values)
74+
plt.title("Expense Distribution by Category")
75+
plt.xlabel("Expense Category")
76+
plt.ylabel("Total Amount")
77+
plt.xticks(rotation=45)
78+
plt.show()
79+
except FileNotFoundError:
80+
print("No expenses found.")
81+
82+
def main():
83+
while True:
84+
print("\nPersonal Finance Manager Menu:")
85+
print("1. Track Expenses")
86+
print("2. View Expenses")
87+
print("3. Generate Spending Report")
88+
print("4. Set Budget")
89+
print("5. Reset Monthly Budget and Expenses")
90+
print("6. Check Remaining Budget")
91+
print("7. Visualize Expense Distribution")
92+
print("8. Exit")
93+
94+
choice = input("Enter your choice (1-8): ")
95+
96+
if choice == "1":
97+
track_expenses()
98+
elif choice == "2":
99+
view_expenses()
100+
elif choice == "3":
101+
generate_spending_report()
102+
elif choice == "4":
103+
set_budget()
104+
elif choice == "5":
105+
reset_monthly_budget()
106+
elif choice == "6":
107+
check_budget()
108+
elif choice == "7":
109+
visualize_expense_distribution()
110+
elif choice == "8":
111+
print("Exiting the Personal Finance Manager.")
112+
break
113+
else:
114+
print("Invalid choice. Please try again.")
115+
116+
117+
if __name__ == "__main__":
118+
main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pandas
2+
matplotlib.pyplot

0 commit comments

Comments
 (0)