GMARTINEZMILLA commited on
Commit
a383324
·
1 Parent(s): f764ae8

feat: generated files

Browse files
Files changed (1) hide show
  1. app.py +20 -16
app.py CHANGED
@@ -122,29 +122,33 @@ elif page == "Customer Analysis":
122
  # Remove the 'CLIENTE' row from sales_data to avoid issues with mixed types
123
  sales_data_filtered = sales_data.drop(index='CLIENTE', errors='ignore')
124
 
125
- # Ensure all values are numeric (optional, but adds robustness)
126
  sales_data_filtered = sales_data_filtered.apply(pd.to_numeric, errors='coerce')
127
 
128
- # Sort manufacturers by percentage of units and get top 10
129
- top_units = all_manufacturers.sort_values(by=all_manufacturers.columns[0], ascending=False).head(10)
 
 
 
130
 
131
- # Sort manufacturers by total sales and get top 10
132
- top_sales = sales_data_filtered.sort_values(by=sales_data_filtered.columns[0], ascending=False).head(10)
133
 
134
- # Combine top manufacturers from both lists
135
- combined_top = pd.concat([top_units, top_sales]).index.unique()
136
 
137
- values = [] # Will store percentages
138
- manufacturers = []
139
- amounts = [] # Will store total sales
 
 
 
140
 
141
- for m in combined_top:
142
- if m in all_manufacturers.index and m in sales_data_filtered.index:
143
- values.append(float(all_manufacturers.loc[m, all_manufacturers.columns[0]]))
144
- manufacturers.append(get_supplier_name(m))
145
- amounts.append(float(sales_data_filtered.loc[m, sales_data_filtered.columns[0]]))
146
 
147
- st.write(f"### Results for top {len(manufacturers)} manufacturers (balanced by units % and total sales):")
148
  for manufacturer, value, amount in zip(manufacturers, values, amounts):
149
  st.write(f"{manufacturer} = {value:.2f}% of units, €{amount:.2f} total sales")
150
 
 
122
  # Remove the 'CLIENTE' row from sales_data to avoid issues with mixed types
123
  sales_data_filtered = sales_data.drop(index='CLIENTE', errors='ignore')
124
 
125
+ # Ensure all values are numeric
126
  sales_data_filtered = sales_data_filtered.apply(pd.to_numeric, errors='coerce')
127
 
128
+ # Combine manufacturers data
129
+ combined_data = pd.DataFrame({
130
+ 'units': all_manufacturers[all_manufacturers.columns[0]],
131
+ 'sales': sales_data_filtered[sales_data_filtered.columns[0]]
132
+ })
133
 
134
+ # Sort by units, then by sales
135
+ combined_data_sorted = combined_data.sort_values(by=['units', 'sales'], ascending=False)
136
 
137
+ # Filter out manufacturers with 0 units
138
+ non_zero_manufacturers = combined_data_sorted[combined_data_sorted['units'] > 0]
139
 
140
+ # If we have less than 3 non-zero manufacturers, add some zero-value ones
141
+ if len(non_zero_manufacturers) < 3:
142
+ zero_manufacturers = combined_data_sorted[combined_data_sorted['units'] == 0].head(3 - len(non_zero_manufacturers))
143
+ manufacturers_to_show = pd.concat([non_zero_manufacturers, zero_manufacturers])
144
+ else:
145
+ manufacturers_to_show = non_zero_manufacturers
146
 
147
+ values = manufacturers_to_show['units'].tolist()
148
+ amounts = manufacturers_to_show['sales'].tolist()
149
+ manufacturers = [get_supplier_name(m) for m in manufacturers_to_show.index]
 
 
150
 
151
+ st.write(f"### Results for top {len(manufacturers)} manufacturers:")
152
  for manufacturer, value, amount in zip(manufacturers, values, amounts):
153
  st.write(f"{manufacturer} = {value:.2f}% of units, €{amount:.2f} total sales")
154