Spaces:
Running
Running
Commit
•
a755ae5
1
Parent(s):
1d56d7a
Update app.py
Browse files
app.py
CHANGED
@@ -164,42 +164,6 @@ if not filtered_df.empty:
|
|
164 |
# Append these rows to the table data
|
165 |
table_data = pd.concat([table_data, saude_row, educacao_row], ignore_index=True)
|
166 |
|
167 |
-
# Convert 'Data_Completa' to datetime format to ensure correct processing
|
168 |
-
temp_data['Data_Completa'] = pd.to_datetime(temp_data['Data_Completa'])
|
169 |
-
|
170 |
-
# Assuming 'Data_Completa' is sorted, if not, you should sort it.
|
171 |
-
# temp_data = temp_data.sort_values(by='Data_Completa', ascending=False)
|
172 |
-
|
173 |
-
# Initialize an empty list to store data including the 'Último ano' sums
|
174 |
-
data_with_last_year = []
|
175 |
-
|
176 |
-
# Iterate over each unique 'Instituição' and 'Conta' combination in 'df'
|
177 |
-
for instituicao in df['Instituição'].unique():
|
178 |
-
for conta in df[df['Instituição'] == instituicao]['Conta'].unique():
|
179 |
-
# Filter temp_data for the current 'Instituição' and 'Conta'
|
180 |
-
filtered_temp = temp_data[(temp_data['Instituição'] == instituicao) & (temp_data['Conta'] == conta)]
|
181 |
-
|
182 |
-
# Get the last 12 periods of 'Data_Completa'
|
183 |
-
last_12_periods = filtered_temp.nlargest(12, 'Data_Completa')
|
184 |
-
|
185 |
-
# Calculate the sum of 'Valor' for these periods
|
186 |
-
last_year_sum = last_12_periods['Valor'].sum()
|
187 |
-
|
188 |
-
# Append this information to the data list
|
189 |
-
data_with_last_year.append({
|
190 |
-
'Conta': conta,
|
191 |
-
'Último ano': last_year_sum
|
192 |
-
})
|
193 |
-
|
194 |
-
# Convert the list to a DataFrame
|
195 |
-
last_year_data = pd.DataFrame(data_with_last_year)
|
196 |
-
|
197 |
-
# Merge this DataFrame with your existing table data to add the 'Último ano' column
|
198 |
-
# Assuming 'table_data' is your existing DataFrame that you want to add the column to
|
199 |
-
# You might need to adjust column names or merge keys based on your actual data structure
|
200 |
-
table_data = table_data.merge(last_year_data, on=['Conta'])
|
201 |
-
|
202 |
-
|
203 |
# Display the table
|
204 |
st.table(table_data)
|
205 |
|
|
|
164 |
# Append these rows to the table data
|
165 |
table_data = pd.concat([table_data, saude_row, educacao_row], ignore_index=True)
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
# Display the table
|
168 |
st.table(table_data)
|
169 |
|