fschwartzer commited on
Commit
a3f2892
1 Parent(s): 03b509e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -88,6 +88,45 @@ col1, col2, col3 = st.columns([col1_width, col2_width, col3_width])
88
 
89
  # Display the Forecasts values in the first column
90
  col1.header('Composição da RLIT')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  labels = table_data['Conta']
92
  sizes = [(i / total_sum) * 100 for i in table_data['Próximos 12 meses']]
93
 
 
88
 
89
  # Display the Forecasts values in the first column
90
  col1.header('Composição da RLIT')
91
+
92
+ tab_df = df[df['Instituição'] == selected_instituicao]
93
+
94
+ data = []
95
+
96
+ for conta in tab_df['Conta'].unique():
97
+ # Filter the DataFrame for the current 'Conta'
98
+ conta_df = tab_df[tab_df['Conta'] == conta]
99
+
100
+ if len(conta_df['Modelo'].unique()) > 1 and "Linear Regression" in conta_df['Modelo'].unique():
101
+ conta_df = conta_df[conta_df['Modelo'] == "Linear Regression"]
102
+
103
+ # Initialize a variable to store the sum for the current 'Conta'
104
+ conta_sum = 0.0
105
+
106
+ # Take the first 'Modelo' for simplicity
107
+ modelo = conta_df['Modelo'].iloc[0]
108
+
109
+ # Iterate over each row in the filtered DataFrame for the current 'Conta'
110
+ for _, row in conta_df.iterrows():
111
+ lines = row['Forecasts'].split('\n')
112
+ for line in lines[:-1]: # Skip the summary line
113
+ if line.strip():
114
+ parts = line.split()
115
+ value = parts[-1]
116
+ try:
117
+ conta_sum += float(value)
118
+ except ValueError:
119
+ print(f"Skipping line unable to convert to float: {line}")
120
+
121
+ # Format the sum as a monetary value
122
+ monetary_value = f'R$ {conta_sum:,.2f}'
123
+
124
+ # Append the data to the list
125
+ data.append({'Conta': conta, 'Modelo': modelo, 'Próximos 12 meses': monetary_value})
126
+
127
+ # Convert the list to a DataFrame
128
+ table_data = pd.DataFrame(data)
129
+
130
  labels = table_data['Conta']
131
  sizes = [(i / total_sum) * 100 for i in table_data['Próximos 12 meses']]
132