fschwartzer commited on
Commit
67830d9
1 Parent(s): 14a3d68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -117,26 +117,29 @@ if not filtered_df.empty:
117
  # Initialize a variable to store the sum for the current 'Conta'
118
  conta_sum = 0.0
119
 
 
 
 
 
120
  # Iterate over each row in the filtered DataFrame for the current 'Conta'
121
  for _, row in conta_df.iterrows():
122
- # Split the 'Forecasts' column's multiline string into lines
 
123
  lines = row['Forecasts'].split('\n')
124
- # For each line, except the last summary line, extract the numeric value and add it to the conta_sum
125
- for line in lines[:-1]: # Skip the last line, which contains the summary
126
- if line.strip(): # Ensure the line is not empty
127
  parts = line.split()
128
- value = parts[-1] # Take the last element as the value
129
  try:
130
  conta_sum += float(value)
131
  except ValueError:
132
- # Handle unexpected lines that cannot be converted to float
133
  print(f"Skipping line unable to convert to float: {line}")
134
 
135
  # Format the sum as a monetary value
136
  monetary_value = f'R$ {conta_sum:,.2f}'
137
 
138
- # Append the sum for the current 'Conta' to the data list
139
- data.append({'Conta': conta, 'Valor Monetário': monetary_value})
140
 
141
  # Convert the list to a DataFrame
142
  table_data = pd.DataFrame(data)
@@ -144,8 +147,8 @@ if not filtered_df.empty:
144
  # Calculate the grand total sum of all 'Conta' values
145
  total_sum = sum(float(row['Valor Monetário'].replace('R$ ', '').replace(',', '')) for row in data)
146
 
147
- # Create a DataFrame for the "Total" row
148
- total_row = pd.DataFrame({'Conta': ['TOTAL'], 'Valor Monetário': [f'R$ {total_sum:,.2f}']})
149
 
150
  # Concatenate the "Total" row with the existing table data
151
  table_data = pd.concat([table_data, total_row], ignore_index=True)
 
117
  # Initialize a variable to store the sum for the current 'Conta'
118
  conta_sum = 0.0
119
 
120
+ # Optionally, handle multiple 'Modelos' by aggregating them
121
+ # For simplicity, here we're just taking the first 'Modelo' found for the 'Conta'
122
+ modelo = conta_df['Modelo'].iloc[0]
123
+
124
  # Iterate over each row in the filtered DataFrame for the current 'Conta'
125
  for _, row in conta_df.iterrows():
126
+ # Extract the numeric value and add it to the conta_sum
127
+ # Assuming 'Forecasts' is already processed correctly above
128
  lines = row['Forecasts'].split('\n')
129
+ for line in lines[:-1]: # Skip the summary line
130
+ if line.strip():
 
131
  parts = line.split()
132
+ value = parts[-1]
133
  try:
134
  conta_sum += float(value)
135
  except ValueError:
 
136
  print(f"Skipping line unable to convert to float: {line}")
137
 
138
  # Format the sum as a monetary value
139
  monetary_value = f'R$ {conta_sum:,.2f}'
140
 
141
+ # Append the 'Conta', 'Modelo', and sum to the data list
142
+ data.append({'Conta': conta, 'Modelo': modelo, 'Valor Monetário': monetary_value})
143
 
144
  # Convert the list to a DataFrame
145
  table_data = pd.DataFrame(data)
 
147
  # Calculate the grand total sum of all 'Conta' values
148
  total_sum = sum(float(row['Valor Monetário'].replace('R$ ', '').replace(',', '')) for row in data)
149
 
150
+ # Create a DataFrame for the "Total" row, without a 'Modelo' value
151
+ total_row = pd.DataFrame({'Conta': ['TOTAL'], 'Modelo': [''], 'Valor Monetário': [f'R$ {total_sum:,.2f}']})
152
 
153
  # Concatenate the "Total" row with the existing table data
154
  table_data = pd.concat([table_data, total_row], ignore_index=True)