Update app.py
Browse files
app.py
CHANGED
@@ -47,11 +47,11 @@ if uploaded_file is not None:
|
|
47 |
st.pyplot(fig1)
|
48 |
|
49 |
# Visualization 2: Monthly Spending Trends (Line Chart)
|
50 |
-
# Convert 'Date' to datetime
|
51 |
-
df['Date'] = pd.to_datetime(df['Date'])
|
52 |
|
53 |
# Extract month-year for grouping and convert the Period to string to avoid JSON serialization issues
|
54 |
-
df['Month'] = df['Date'].
|
55 |
|
56 |
# Group by month and calculate the total amount spent per month
|
57 |
monthly_expenses = df.groupby('Month')['Amount'].sum()
|
|
|
47 |
st.pyplot(fig1)
|
48 |
|
49 |
# Visualization 2: Monthly Spending Trends (Line Chart)
|
50 |
+
# Convert 'Date' to datetime and remove time part
|
51 |
+
df['Date'] = pd.to_datetime(df['Date']).dt.date # Keep only the date, no time
|
52 |
|
53 |
# Extract month-year for grouping and convert the Period to string to avoid JSON serialization issues
|
54 |
+
df['Month'] = df['Date'].apply(lambda x: x.strftime('%Y-%m')) # Extract Year-Month as string
|
55 |
|
56 |
# Group by month and calculate the total amount spent per month
|
57 |
monthly_expenses = df.groupby('Month')['Amount'].sum()
|