GMARTINEZMILLA commited on
Commit
aed9cd2
·
1 Parent(s): c6a929c

feat: generated files

Browse files
Files changed (1) hide show
  1. app.py +16 -20
app.py CHANGED
@@ -101,40 +101,36 @@ elif page == "Customer Analysis":
101
  if not customer_data.empty and not customer_euros.empty:
102
  st.write(f"### Analysis for Customer {customer_code}")
103
 
104
- # Ensure all manufacturer codes are strings
105
- all_manufacturers = customer_data.iloc[:, 1:].T[customer_data.iloc[:, 1:].T[customer_data.index[0]] > 0]
106
  all_manufacturers.index = all_manufacturers.index.astype(str)
107
 
108
- # Convert to numeric and handle any non-numeric values
109
- all_manufacturers = all_manufacturers.apply(pd.to_numeric, errors='coerce')
110
- customer_euros = customer_euros.apply(pd.to_numeric, errors='coerce')
111
 
 
112
  top_units = all_manufacturers.sort_values(by=customer_data.index[0], ascending=False).head(10)
113
 
114
- # Ensure we're working with numeric data for sorting
115
- numeric_euros = customer_euros.select_dtypes(include=[np.number])
116
- if not numeric_euros.empty:
117
- top_sales = numeric_euros.iloc[0].sort_values(ascending=False).head(10)
118
- top_sales.index = top_sales.index.astype(str)
119
- else:
120
- st.warning("No numeric sales data available for this customer.")
121
- top_sales = pd.Series()
122
 
 
123
  combined_top = pd.concat([top_units, top_sales]).index.unique()
124
 
125
- values = []
126
  manufacturers = []
127
- amounts = []
128
 
129
  for m in combined_top:
130
- if m in all_manufacturers.index and m in customer_euros.columns:
131
- values.append(all_manufacturers[m])
132
  manufacturers.append(get_supplier_name(m))
133
- amounts.append(customer_euros[m].iloc[0])
134
 
135
- st.write(f"### Results for top {len(manufacturers)} manufacturers (balanced by units and sales):")
136
  for manufacturer, value, amount in zip(manufacturers, values, amounts):
137
- st.write(f"{manufacturer} = {value:.4f} units, €{amount:.2f}")
138
 
139
  if manufacturers: # Only create the chart if we have data
140
  fig = radar_chart(manufacturers, values, amounts, f'Radar Chart for Top {len(manufacturers)} Manufacturers of Customer {customer_code}')
 
101
  if not customer_data.empty and not customer_euros.empty:
102
  st.write(f"### Analysis for Customer {customer_code}")
103
 
104
+ # Get percentage of units sold for each manufacturer
105
+ all_manufacturers = customer_data.iloc[:, 1:-2].T # Exclude CLIENTE and last two columns
106
  all_manufacturers.index = all_manufacturers.index.astype(str)
107
 
108
+ # Get total sales for each manufacturer
109
+ sales_data = customer_euros.iloc[:, 1:].T # Exclude CLIENTE column
110
+ sales_data.index = sales_data.index.astype(str)
111
 
112
+ # Sort manufacturers by percentage of units and get top 10
113
  top_units = all_manufacturers.sort_values(by=customer_data.index[0], ascending=False).head(10)
114
 
115
+ # Sort manufacturers by total sales and get top 10
116
+ top_sales = sales_data.sort_values(by=customer_euros.index[0], ascending=False).head(10)
 
 
 
 
 
 
117
 
118
+ # Combine top manufacturers from both lists
119
  combined_top = pd.concat([top_units, top_sales]).index.unique()
120
 
121
+ values = [] # Will store percentages
122
  manufacturers = []
123
+ amounts = [] # Will store total sales
124
 
125
  for m in combined_top:
126
+ if m in all_manufacturers.index and m in sales_data.index:
127
+ values.append(all_manufacturers.loc[m, customer_data.index[0]])
128
  manufacturers.append(get_supplier_name(m))
129
+ amounts.append(sales_data.loc[m, customer_euros.index[0]])
130
 
131
+ st.write(f"### Results for top {len(manufacturers)} manufacturers (balanced by units % and total sales):")
132
  for manufacturer, value, amount in zip(manufacturers, values, amounts):
133
+ st.write(f"{manufacturer} = {value:.2f}% of units, €{amount:.2f} total sales")
134
 
135
  if manufacturers: # Only create the chart if we have data
136
  fig = radar_chart(manufacturers, values, amounts, f'Radar Chart for Top {len(manufacturers)} Manufacturers of Customer {customer_code}')