From f7347a1b450f384fd310e4c789e9eb95aa30f009 Mon Sep 17 00:00:00 2001 From: RAYMOND Olivier <34789438+Isdinval@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:08:13 +0200 Subject: [PATCH] Update dashboard_CLOUD.py --- dashboard_CLOUD.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/dashboard_CLOUD.py b/dashboard_CLOUD.py index ab3af76..879a00f 100644 --- a/dashboard_CLOUD.py +++ b/dashboard_CLOUD.py @@ -300,9 +300,16 @@ def main(): # Filter data based on selected feature filtered_data = customer_data_copy.copy() # Avoid modifying original data - # Separate data for full dataset and current customer - full_data_values = customer_data_copy[selected_feature] - customer_value = customer_data_copy[selected_feature].iloc[0] + # Sort data (ascending order by default) + sorted_data = filtered_data.sort_values(by=selected_feature) + + # Separate data for full dataset (sorted) and current customer + full_data_values = sorted_data[selected_feature] + customer_value = customer_data_copy[selected_feature].iloc[customer_index] + + # Find the new index of the current customer in the sorted data + customer_index = sorted_data[sorted_data[selected_feature] == customer_value].index.tolist()[0] + st.write("full_data_values") st.write(full_data_values) st.write("customer_value") @@ -311,21 +318,20 @@ def main(): # Create bar chart with highlighting plt.figure(figsize=(10, 6)) # Adjust figure size for better visualization - # Plot full dataset data with a grey color + # Plot full dataset data with a grey color (using sorted values) plt.bar(range(len(full_data_values)), full_data_values, color='gray', alpha=0.7, label='All Clients') - # Highlight current customer with a red bar + # Highlight current customer with a red bar (using new index) plt.bar(customer_index, customer_value, color='red', label='Current Customer') plt.xlabel('Customer Index') plt.ylabel(selected_feature) - plt.title(f'{selected_feature} Distribution') + plt.title(f'{selected_feature} Distribution (Sorted)') plt.xticks(range(len(full_data_values)), rotation=45, ha='right') # Rotate x-axis labels for better readability if many customers plt.legend() plt.tight_layout() st.pyplot(plt.gcf()) - # # ========================================================================= # # COMPARATIVE ANALYSIS USING GRAPHS # # ======================================================================== @@ -343,7 +349,7 @@ def main(): # # Separate data for full dataset and current customer # full_data_values = customer_data_copy[selected_feature] - # customer_value = customer_data_copy[selected_feature].iloc[0] + # customer_value = customer_data_copy[selected_feature].iloc[customer_index] # st.write("full_data_values") # st.write(full_data_values) # st.write("customer_value")