engralimalik commited on
Commit
77dc4ed
·
verified ·
1 Parent(s): 631a831

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
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'].dt.to_period('M').astype(str) # Convert Period to string
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()