-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
52 lines (41 loc) · 1.62 KB
/
app.py
File metadata and controls
52 lines (41 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import streamlit as st
import pandas as pd
# Initialize an empty DataFrame to store expenses
expenses = pd.DataFrame(columns=["Description", "Amount", "Category"])
# Function to add an expense entry
def add_expense(description, amount, category):
global expenses
new_expense = pd.DataFrame([[description, amount, category]], columns=["Description", "Amount", "Category"])
expenses = pd.concat([expenses, new_expense], ignore_index=True)
# Function to get total expenses and summary by category
def get_summary():
if expenses.empty:
st.write("No expenses logged yet.")
return
st.subheader("Expense Summary")
total_expense = expenses["Amount"].sum()
st.write(f"**Total Expense: ${total_expense:.2f}**")
# Show summary by category
category_summary = expenses.groupby("Category")["Amount"].sum().reset_index()
st.write("**Expenses by Category:**")
st.dataframe(category_summary)
# Streamlit UI
st.title("Expense Tracker")
# Expense form
st.subheader("Add New Expense")
with st.form(key='expense_form'):
description = st.text_input("Description")
amount = st.number_input("Amount", min_value=0.0, format="%.2f")
category = st.selectbox("Category", ["Food", "Transport", "Utilities", "Entertainment", "Other"])
submit_button = st.form_submit_button(label="Add Expense")
if submit_button:
add_expense(description, amount, category)
st.success("Expense added successfully!")
# Display expenses
st.subheader("All Expenses")
if not expenses.empty:
st.dataframe(expenses)
else:
st.write("No expenses to show yet.")
# Show the summary
get_summary()