Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
107 |
-
|
108 |
|
109 |
-
# Create
|
110 |
data = []
|
111 |
|
112 |
-
#
|
113 |
-
|
|
|
|
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
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 |
-
|
|
|
|
|
|
|
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({'
|
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)
|