Spaces:
Sleeping
Sleeping
Commit
•
bec769c
1
Parent(s):
576a621
Update app.py
Browse files
app.py
CHANGED
@@ -162,6 +162,16 @@ if not filtered_df.empty:
|
|
162 |
# Append these rows to the table data
|
163 |
table_data = pd.concat([table_data, saude_row, educacao_row], ignore_index=True)
|
164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
# Display the table
|
166 |
st.table(table_data)
|
167 |
|
|
|
162 |
# Append these rows to the table data
|
163 |
table_data = pd.concat([table_data, saude_row, educacao_row], ignore_index=True)
|
164 |
|
165 |
+
# Calculate the sum of the last 12 periods for each "Conta" of each "Instituição"
|
166 |
+
last_12_periods_sums = df.groupby(['Instituição', 'Conta']) \
|
167 |
+
.apply(lambda x: x.sort_values(by='Period', ascending=False).head(12)['Value'].sum()) \
|
168 |
+
.reset_index(name='Último ano')
|
169 |
+
|
170 |
+
# Merge this sum back into your table_data DataFrame
|
171 |
+
# This assumes table_data already exists and contains columns for 'Instituição' and 'Conta'
|
172 |
+
table_data = pd.merge(table_data, last_12_periods_sums, on=['Instituição', 'Conta'], how='left')
|
173 |
+
|
174 |
+
|
175 |
# Display the table
|
176 |
st.table(table_data)
|
177 |
|