Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -136,29 +136,24 @@ if viz_button:
|
|
| 136 |
|
| 137 |
# Expenses Over Time Line Chart with Title, Labels, and Point Labels
|
| 138 |
st.subheader("Expenses Over Time")
|
| 139 |
-
|
| 140 |
|
|
|
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
monthly_summary = monthly_expenses.groupby('Month_Year')['Amount'].sum().reset_index()
|
| 147 |
-
monthly_summary['Month_Year'] = monthly_summary['Month_Year'].dt.to_timestamp() # Convert back to timestamp for plotting
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
ax.set_ylabel("Amount Spent (£)", labelpad=15) # Y-axis label
|
| 153 |
-
|
| 154 |
-
# Formatting the x-axis to show Month-Year
|
| 155 |
-
ax.xaxis.set_major_formatter(mdates.DateFormatter('%b %Y'))
|
| 156 |
-
plt.xticks(rotation=45)
|
| 157 |
-
|
| 158 |
-
# Adding labels to each point
|
| 159 |
-
for date, amount in zip(monthly_summary['Month_Year'], monthly_summary['Amount']):
|
| 160 |
-
ax.text(date, amount + 0.05, f'{amount:.2f}', ha='right')
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
st.pyplot(fig)
|
| 164 |
|
|
|
|
| 136 |
|
| 137 |
# Expenses Over Time Line Chart with Title, Labels, and Point Labels
|
| 138 |
st.subheader("Expenses Over Time")
|
|
|
|
| 139 |
|
| 140 |
+
monthly_df = st.session_state['expenses'].copy()
|
| 141 |
|
| 142 |
+
monthly_df['Date'] = pd.to_datetime(monthly_df['Date'])
|
| 143 |
+
|
| 144 |
+
# Extract month and year for grouping
|
| 145 |
+
monthly_df['Month'] = monthly_df['Date'].dt.to_period('M')
|
|
|
|
|
|
|
| 146 |
|
| 147 |
+
# Group by the new "Month" column and aggregate the "Amount"
|
| 148 |
+
monthly_expenses = monthly_df.groupby('Month')['Amount'].sum().reset_index()
|
| 149 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
+
plt.plot(monthly_expenses['Month'], monthly_expenses['Amount'], marker='o')
|
| 152 |
+
plt.title('Monthly Expenses')
|
| 153 |
+
plt.xlabel('Month')
|
| 154 |
+
plt.ylabel('Amount')
|
| 155 |
+
plt.grid(True)
|
| 156 |
+
plt.show()
|
| 157 |
|
| 158 |
st.pyplot(fig)
|
| 159 |
|