fschwartzer commited on
Commit
bdd90e4
1 Parent(s): 23a489a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -103,30 +103,33 @@ else:
103
  col3 = st.columns(1) # You can use st.columns(1) to create a single column layout
104
 
105
  if not filtered_df.empty:
106
- tab_df = df[(df['Instituição'] == selected_instituicao)]
107
- data_string = tab_df['Forecasts'].iloc[0]
108
 
109
- # Create a list to store data for each period
110
  data = []
111
 
112
- # Split the string into lines
113
- lines = data_string.split('\n')
 
 
114
 
115
- # Iterate through the lines and extract the values
116
- for line in lines[:-2]:
117
- period, value = line.split()
118
- num_float = float(value)
119
- monetary_value = f'R$ {num_float:,.2f}' # Adding commas for thousands separator
120
- data.append({'Período': int(period), 'Valor Monetário': monetary_value})
121
 
122
- # Create a DataFrame from the list
 
 
 
123
  table_data = pd.DataFrame(data)
124
 
125
- # Calculate the sum
126
  total_sum = table_data['Valor Monetário'].str.replace('R$ ', '').str.replace(',', '').astype(float).sum()
127
 
128
  # Create a DataFrame for the "Total" row
129
- total_row = pd.DataFrame({'Período': ['Total'], 'Valor Monetário': [f'R$ {total_sum:,.2f}']})
130
 
131
  # Concatenate the "Total" row with the existing table data
132
  table_data = pd.concat([table_data, total_row], ignore_index=True)
 
103
  col3 = st.columns(1) # You can use st.columns(1) to create a single column layout
104
 
105
  if not filtered_df.empty:
106
+ # Filter the DataFrame for the selected institution
107
+ tab_df = df[df['Instituição'] == selected_instituicao]
108
 
109
+ # Create an empty list to store data
110
  data = []
111
 
112
+ # Iterate through each unique 'Conta' in the filtered DataFrame
113
+ for conta in tab_df['Conta'].unique():
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})
124
+
125
+ # Convert the list to a DataFrame
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}']})
133
 
134
  # Concatenate the "Total" row with the existing table data
135
  table_data = pd.concat([table_data, total_row], ignore_index=True)