fschwartzer commited on
Commit
3a1ee0e
1 Parent(s): b0e5aac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -23
app.py CHANGED
@@ -192,30 +192,44 @@ if not filtered_df.empty:
192
  last_df['Últimos 12 meses'] = last_df['Últimos 12 meses'].apply(format_currency)
193
  table_data = pd.merge(table_data, last_df)
194
 
195
- # Calculate the grand total sum of all 'Conta' values
196
- total_sum = table_data['Próximos 12 meses'].replace(r'R\$ ', '', regex=True).replace(',', '', regex=True).astype(float).sum()
197
-
198
- total_sum_prev = table_data['Últimos 12 meses'].replace(r'R\$ ', '', regex=True).replace(',', '', regex=True).astype(float).sum()
199
-
200
- # Append the "Total" row
201
- total_row = pd.DataFrame({'Conta': ['TOTAL (RLIT)'], 'Modelo': [''], 'Próximos 12 meses': [f'R$ {total_sum:,.2f}'], 'Últimos 12 meses': [f'R$ {total_sum_prev:,.2f}']})
202
- table_data = pd.concat([table_data, total_row], ignore_index=True)
203
-
204
- # Calculate and append the rows for "Saúde (12% da RLIT)" and "Educação (25% da RLIT)"
205
- saude_value = total_sum * 0.15
206
- educacao_value = total_sum * 0.25
207
- saude_value_prev = total_sum_prev * 0.15
208
- educacao_value_prev = total_sum_prev * 0.25
209
- saude_row = pd.DataFrame({'Conta': ['Saúde (15% da RLIT)'], 'Modelo': [''], 'Próximos 12 meses': [f'R$ {saude_value:,.2f}'], 'Últimos 12 meses': [f'R$ {saude_value_prev:,.2f}']})
210
- educacao_row = pd.DataFrame({'Conta': ['Educação (25% da RLIT)'], 'Modelo': [''], 'Próximos 12 meses': [f'R$ {educacao_value:,.2f}'], 'Últimos 12 meses': [f'R$ {educacao_value_prev:,.2f}']})
211
-
212
- # Append these rows to the table data
213
- table_data = pd.concat([table_data, saude_row, educacao_row], ignore_index=True)
214
-
215
- table_data.fillna('-', inplace=True)
 
 
 
 
 
 
 
 
 
 
 
216
 
217
- # Display the table
218
- st.table(table_data)
 
 
 
219
 
220
  else:
221
  col3.warning('No data available for the selected filters.')
 
192
  last_df['Últimos 12 meses'] = last_df['Últimos 12 meses'].apply(format_currency)
193
  table_data = pd.merge(table_data, last_df)
194
 
195
+ try:
196
+ # Removing 'R$ ' and commas from the monetary columns for conversion to float
197
+ # Use regex=True in replace() method to ensure all instances are replaced
198
+ table_data['Próximos 12 meses'] = table_data['Próximos 12 meses'].replace(r'R\$ ', '', regex=True).replace(',', '', regex=True).astype(float)
199
+ table_data['Últimos 12 meses'] = table_data['Últimos 12 meses'].replace(r'R\$ ', '', regex=True).replace(',', '', regex=True).astype(float)
200
+
201
+ # Calculate the grand total sum of 'Próximos 12 meses' and 'Últimos 12 meses' values
202
+ total_sum = table_data['Próximos 12 meses'].sum()
203
+ total_sum_prev = table_data['Últimos 12 meses'].sum()
204
+
205
+ # Append the "Total" row
206
+ total_row = pd.DataFrame({
207
+ 'Conta': ['TOTAL (RLIT)'],
208
+ 'Modelo': [''],
209
+ 'Próximos 12 meses': [f'R$ {total_sum:,.2f}'],
210
+ 'Últimos 12 meses': [f'R$ {total_sum_prev:,.2f}']
211
+ })
212
+ table_data = pd.concat([table_data, total_row], ignore_index=True)
213
+
214
+ # Additional rows calculations and appending
215
+ # Assuming percentages for health and education as previously mentioned
216
+ saude_value = total_sum * 0.15
217
+ educacao_value = total_sum * 0.25
218
+ saude_value_prev = total_sum_prev * 0.15
219
+ educacao_value_prev = total_sum_prev * 0.25
220
+ saude_row = pd.DataFrame({'Conta': ['Saúde (15% da RLIT)'], 'Modelo': [''], 'Próximos 12 meses': [f'R$ {saude_value:,.2f}'], 'Últimos 12 meses': [f'R$ {saude_value_prev:,.2f}']})
221
+ educacao_row = pd.DataFrame({'Conta': ['Educação (25% da RLIT)'], 'Modelo': [''], 'Próximos 12 meses': [f'R$ {educacao_value:,.2f}'], 'Últimos 12 meses': [f'R$ {educacao_value_prev:,.2f}']})
222
+
223
+ # Append these rows to the table data
224
+ table_data = pd.concat([table_data, saude_row, educacao_row], ignore_index=True)
225
+
226
+ table_data.fillna('-', inplace=True)
227
 
228
+ # Display the table using Streamlit
229
+ st.table(table_data)
230
+
231
+ except Exception as e:
232
+ st.error(f"Error in processing data: {str(e)}")
233
 
234
  else:
235
  col3.warning('No data available for the selected filters.')