Spaces:
Sleeping
Sleeping
Commit
·
a383324
1
Parent(s):
f764ae8
feat: generated files
Browse files
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
|
126 |
sales_data_filtered = sales_data_filtered.apply(pd.to_numeric, errors='coerce')
|
127 |
|
128 |
-
#
|
129 |
-
|
|
|
|
|
|
|
130 |
|
131 |
-
# Sort
|
132 |
-
|
133 |
|
134 |
-
#
|
135 |
-
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
|
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
|
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 |
|