fschwartzer commited on
Commit
2864c62
1 Parent(s): bdd90e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -114,10 +114,21 @@ if not filtered_df.empty:
114
  # Filter the DataFrame for the current 'Conta'
115
  conta_df = tab_df[tab_df['Conta'] == conta]
116
 
117
- # Assuming 'Forecasts' column contains the monetary values for each 'Conta'
118
- # Convert all values in 'Forecasts' to float, sum them, and format as monetary value
119
- total_value = conta_df['Forecasts'].astype(float).sum()
120
- monetary_value = f'R$ {total_value:,.2f}'
 
 
 
 
 
 
 
 
 
 
 
121
 
122
  # Append the sum for the current 'Conta' to the data list
123
  data.append({'Conta': conta, 'Valor Monetário': monetary_value})
@@ -126,7 +137,7 @@ if not filtered_df.empty:
126
  table_data = pd.DataFrame(data)
127
 
128
  # Calculate the grand total sum of all 'Conta' values
129
- total_sum = table_data['Valor Monetário'].str.replace('R$ ', '').str.replace(',', '').astype(float).sum()
130
 
131
  # Create a DataFrame for the "Total" row
132
  total_row = pd.DataFrame({'Conta': ['TOTAL'], 'Valor Monetário': [f'R$ {total_sum:,.2f}']})
@@ -138,4 +149,4 @@ if not filtered_df.empty:
138
  st.table(table_data)
139
 
140
  else:
141
- col3.warning('No data available for the selected filters.')
 
114
  # Filter the DataFrame for the current 'Conta'
115
  conta_df = tab_df[tab_df['Conta'] == conta]
116
 
117
+ # Initialize a variable to store the sum for the current 'Conta'
118
+ conta_sum = 0.0
119
+
120
+ # Iterate over each row in the filtered DataFrame for the current 'Conta'
121
+ for _, row in conta_df.iterrows():
122
+ # Split the 'Forecasts' column's multiline string into lines
123
+ lines = row['Forecasts'].split('\n')
124
+ # For each line, extract the numeric value and add it to the conta_sum
125
+ for line in lines:
126
+ if line.strip(): # Ensure the line is not empty
127
+ _, value = line.split()
128
+ conta_sum += float(value)
129
+
130
+ # Format the sum as a monetary value
131
+ monetary_value = f'R$ {conta_sum:,.2f}'
132
 
133
  # Append the sum for the current 'Conta' to the data list
134
  data.append({'Conta': conta, 'Valor Monetário': monetary_value})
 
137
  table_data = pd.DataFrame(data)
138
 
139
  # Calculate the grand total sum of all 'Conta' values
140
+ total_sum = sum(float(row['Valor Monetário'].replace('R$ ', '').replace(',', '')) for row in data)
141
 
142
  # Create a DataFrame for the "Total" row
143
  total_row = pd.DataFrame({'Conta': ['TOTAL'], 'Valor Monetário': [f'R$ {total_sum:,.2f}']})
 
149
  st.table(table_data)
150
 
151
  else:
152
+ col3.warning('No data available for the selected filters.')