AMKhakbaz commited on
Commit
ea8e2fe
·
verified ·
1 Parent(s): fc8e87b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +296 -290
app.py CHANGED
@@ -544,319 +544,325 @@ import streamlit as st
544
 
545
  st.markdown('[Click to register a suggestion or comment](https://docs.google.com/forms/d/e/1FAIpQLScLyP7bBbqMfGdspjL7Ij64UZ6v2KjqjKNbm8gwEsgWsFs_Qg/viewform?usp=header)')
546
 
547
- st.subheader("Displaying the first few rows of the DataFrame")
548
- st.dataframe(df.head())
549
 
550
- cols = edit_strings(df.columns)
551
- cols = sorted(list(set(cols)))
552
-
553
- main_option = st.selectbox("Please select an option:", ["Tabulation", "Funnel Analysis", "Segmentation Analysis", "Hypothesis test", "Machine Learning", "Coding"])
554
-
555
- if main_option == "Tabulation":
556
- st.header("Tabulation Analysis")
557
-
558
- tabulation_option = st.selectbox("Please select the type of analysis:", ["Univariate", "Multivariate", "All"])
559
-
560
- if tabulation_option == "All":
561
-
562
- st.sidebar.header("Settings")
563
-
564
- main_dict = {"single": [], "multi": [], "score": []}
565
-
566
- st.sidebar.subheader("Main")
567
- main_dict["single"] = st.sidebar.multiselect(
568
- 'Main: Single answer questions',
569
- cols,
570
- default=[]
571
- )
572
-
573
- main_dict["multi"] = st.sidebar.multiselect(
574
- 'Main: Multi answer questions',
575
- cols,
576
- default=[]
577
- )
578
-
579
- main_dict["score"] = st.sidebar.multiselect(
580
- 'Main: Score answer questions',
581
- cols,
582
- default=[]
583
- )
584
-
585
- follow_dict = {"single": [], "multi": [], "score": []}
586
-
587
- st.sidebar.subheader("Follow")
588
- follow_dict["single"] = st.sidebar.multiselect(
589
- 'Follow: Single answer questions',
590
- cols,
591
- default=[]
592
- )
593
-
594
- follow_dict["multi"] = st.sidebar.multiselect(
595
- 'Follow: Multi answer questions',
596
- cols,
597
- default=[]
598
- )
599
-
600
- follow_dict["score"] = st.sidebar.multiselect(
601
- 'Follow: Score answer questions',
602
- cols,
603
- default=[]
604
- )
605
-
606
- all_tabulation(df, main_dict, follow_dict)
607
-
608
- elif tabulation_option == "Univariate":
609
- uni_option = st.selectbox("Select the type of univariate analysis:", ["Multiple answer", "Single answer", "Score answer"])
610
-
611
- if uni_option == "Single answer":
612
- var = st.text_input("Please enter the name of the desired column:")
613
- if var:
614
- if var in df.columns:
615
- result_df = single_answer(df[var])
616
- st.subheader("Univariate Analysis Results")
617
- st.dataframe(result_df)
618
-
619
- fig = figo('Bar', result_df["Percentage"][:-1, ], title='Percentage Histogram', xlabel=var, ylabel='Percentage', colorscale='Plotly3')
620
- st.plotly_chart(fig, use_container_width=True)
621
- else:
622
- st.error("The entered column was not found.")
623
- elif uni_option == "Multiple answer":
624
- var = st.text_input("Please enter the name of the desired column:")
625
- if var:
626
- matching_cols = [col for col in df.columns if is_matching_pattern(col, var)]
627
- if matching_cols:
628
- subset_df = df[matching_cols]
629
- result_df = multi_answer(subset_df)
 
 
 
 
 
 
 
630
 
631
- st.subheader("Multiple Answer Analysis Results")
 
 
 
 
 
 
 
 
 
 
 
632
  st.dataframe(result_df)
633
 
634
- fig = figo('Bar', result_df["Percentage"][:-1], title='Percentage Histogram', xlabel=var, ylabel='Percentage', colorscale='Plotly3')
635
  st.plotly_chart(fig, use_container_width=True)
636
  else:
637
  st.error("No columns matching the entered pattern were found.")
638
-
639
- elif uni_option == "Score answer":
640
- var = st.text_input("Please enter the name of the desired column:")
641
- if var:
642
- subset_df = df[var]
643
- result_df = score_answer(subset_df)
644
-
645
- st.subheader("Score Answer Analysis Results")
646
- st.dataframe(result_df)
647
-
648
- fig = figo('Bar', result_df["Percentage"][:-2], title='Percentage Histogram', xlabel=var, ylabel='Percentage', colorscale='Plotly3')
649
- st.plotly_chart(fig, use_container_width=True)
650
- else:
651
- st.error("No columns matching the entered pattern were found.")
652
-
653
- elif tabulation_option == "Multivariate":
654
- st.subheader("Multivariate Analysis")
655
- var1 = st.text_input("Please enter the name of the first column:")
656
- var2 = st.text_input("Please enter the name of the second column:")
657
-
658
- if var1 and var2:
659
- type1 = st.selectbox("Select the type of analysis for the first column:", ["Multiple answer", "Single answer"], key='type1')
660
- type2 = st.selectbox("Select the type of analysis for the second column:", ["Multiple answer", "Single answer", "Score answer"], key='type2')
661
-
662
- if type1 == "Single answer" and type2 == "Single answer":
663
- percentile_df, frequency_df = two_variable_ss(df[[var1, var2]], var1, var2)
664
- st.subheader("Percentage Table")
665
- st.write(z_test_data(percentile_df))
666
-
667
- st.subheader("Frequency Table")
668
- st.dataframe(frequency_df)
669
-
670
- row, col = df.shape
671
- fig = figo('Scatter', percentile_df.iloc[:-1,:], title='Percentage Scatter plot', width=(col*5)+5, height=(row*25) + 10)
672
- st.plotly_chart(fig, use_container_width=True)
673
-
674
- elif type1 == "Single answer" and type2 == "Multiple answer":
675
- matching_cols = [col for col in df.columns if is_matching_pattern(col, var2)]
676
- if matching_cols:
677
- percentile_df, frequency_df = two_variable_sm(df[[var1] + matching_cols], var1, matching_cols)
678
- st.subheader("Percentage Table")
679
- st.write(z_test_data(percentile_df))
680
-
681
- st.subheader("Frequency Table")
682
- st.dataframe(frequency_df)
683
-
684
- row, col = df.shape
685
- fig = figo('Scatter', percentile_df.iloc[:-1,:], title='Percentage Scatter plot', width=(col*5)+5, height=(row*25) + 10)
686
- st.plotly_chart(fig, use_container_width=True)
687
 
688
- else:
689
- st.error("No columns matching the entered pattern were found.")
690
-
691
- elif type1 == "Multiple answer" and type2 == "Multiple answer":
692
- matching_cols1 = [col for col in df.columns if is_matching_pattern(col, var1)]
693
- matching_cols2 = [col for col in df.columns if is_matching_pattern(col, var2)]
694
- if matching_cols1 and matching_cols2:
695
- percentile_df, frequency_df = two_variable_mm(df[matching_cols1 + matching_cols2], matching_cols1, matching_cols2)
 
 
 
696
  st.subheader("Percentage Table")
697
  st.write(z_test_data(percentile_df))
698
-
699
  st.subheader("Frequency Table")
700
  st.dataframe(frequency_df)
701
-
702
  row, col = df.shape
703
  fig = figo('Scatter', percentile_df.iloc[:-1,:], title='Percentage Scatter plot', width=(col*5)+5, height=(row*25) + 10)
704
  st.plotly_chart(fig, use_container_width=True)
705
-
706
- elif type1 == "Single answer" and type2 == "Score answer":
707
-
708
- mean_df = two_variable_ssc(df[[var1, var2]], var1, var2)
709
- st.subheader("Mean Table")
710
- st.write(t_test_data(mean_df))
711
-
712
- row, col = df.shape
713
- fig = figo('Bar', mean_df["Mean"][:-1], title='Mean Histogram', xlabel=var1, ylabel='Mean', colorscale='Plotly3')
714
- st.plotly_chart(fig, use_container_width=True)
715
-
716
-
717
- elif type1 == "Multiple answer" and type2 == "Score answer":
718
- matching_cols1 = [col for col in df.columns if is_matching_pattern(col, var1)]
719
- if matching_cols1:
720
- mean_df = two_variable_msc(df[matching_cols1 + [var2]], matching_cols1, var2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
721
  st.subheader("Mean Table")
722
  st.write(t_test_data(mean_df))
723
-
724
  row, col = df.shape
725
  fig = figo('Bar', mean_df["Mean"][:-1], title='Mean Histogram', xlabel=var1, ylabel='Mean', colorscale='Plotly3')
726
- st.plotly_chart(fig, use_container_width=True)
727
- else:
728
- st.info("This section of the program is under development.")
729
-
730
- elif main_option == "Funnel Analysis":
731
- st.header("Funnel")
732
-
733
- st.sidebar.header("Funnel Settings")
734
- single_list = st.sidebar.multiselect(
735
- 'Single answer questions',
736
- cols,
737
- default=[]
738
- )
739
-
740
- multi_list = st.sidebar.multiselect(
741
- 'Multi answer questions',
742
- cols,
743
- default=[]
744
- )
745
- selected_dict = {}
746
-
747
- for option in single_list:
748
- selected_dict[option] = "Single"
749
- for option in multi_list:
750
- selected_dict[option] = "Multi"
751
-
752
- funnel_frequency, funnel_percentage = funnel(df, selected_dict)
753
- st.subheader("Percentage Table")
754
- st.dataframe(funnel_percentage)
755
-
756
- st.subheader("Frequency Table")
757
- st.dataframe(funnel_frequency)
758
-
759
- st.sidebar.header("Chart Settings")
760
- bar_columns = st.sidebar.multiselect('Which columns should be displayed as bar charts?', sorted(funnel_percentage.columns))
761
- line_columns = st.sidebar.multiselect('Which columns should be displayed as line charts?', sorted(funnel_percentage.columns))
762
-
763
- funnel_percentage_cleaned = funnel_percentage.dropna(axis=0, how='all')
764
-
765
- fig = go.Figure()
766
-
767
- # Define modern and diverse color palette
768
- modern_colors = [
769
- "#FF6F61", "#6B5B95", "#88B04B", "#F7CAC9", "#92A8D1",
770
- "#955251", "#B565A7", "#009B77", "#DD4124", "#45B8AC"
771
- ]
772
-
773
- # Add Bar traces with transparency and custom colors
774
- for idx, col in enumerate(bar_columns):
775
- funnel_percentage_col = funnel_percentage_cleaned[col]
776
- fig.add_trace(
777
- go.Bar(
778
- x=funnel_percentage_cleaned.index,
779
- y=funnel_percentage_col,
780
- name=col,
781
- marker_color=modern_colors[idx % len(modern_colors)], # Cycle through colors
782
- opacity=0.8 # Set transparency
783
- )
784
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
785
 
786
- # Add Line traces with transparency and custom colors
787
- for idx, col in enumerate(line_columns):
788
- funnel_percentage_col = funnel_percentage_cleaned[col]
789
- fig.add_trace(
790
- go.Scatter(
791
- x=funnel_percentage_cleaned.index,
792
- y=funnel_percentage_col,
793
- mode='lines',
794
- name=col,
795
- line=dict(color=modern_colors[(idx + len(bar_columns)) % len(modern_colors)]), # Cycle through colors
796
- opacity=0.8 # Set transparency
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
797
  )
 
 
 
 
 
 
 
 
798
  )
799
-
800
- fig.update_layout(
801
- title="Combined Bar and Line Chart",
802
- xaxis_title="Brands",
803
- yaxis_title="Percentage",
804
- template="plotly_dark",
805
- barmode="group",
806
- xaxis=dict(tickmode='linear')
807
- )
808
 
809
- st.plotly_chart(fig)
810
-
811
- elif main_option == "Segmentation Analysis":
812
- st.header("Segmentation Analysis")
813
-
814
- st.sidebar.header("Selection of questions")
815
- single_list = st.sidebar.multiselect(
816
- 'Single answer questions',
817
- cols,
818
- default=[]
819
- )
820
-
821
- multi_list = st.sidebar.multiselect(
822
- 'Multi answer questions',
823
- cols,
824
- default=[]
825
- )
826
-
827
- score_list = st.sidebar.multiselect(
828
- 'Score answer questions',
829
- cols,
830
- default=[]
831
- )
832
-
833
- matching_cols1 = []
834
- for i in multi_list:
835
- matching_cols1 += [col for col in df.columns if is_matching_pattern(col, i)]
836
-
837
- df_clean = process_dataframe(df[single_list + matching_cols1])
838
- st.subheader("Selected Table")
839
- st.dataframe(df_clean)
840
-
841
- linkage_method = st.sidebar.selectbox("Select the Linkage Method of Segmentation Analysis:", ['average', 'single', 'complete', 'weighted', 'centroid', 'median', 'ward'])
842
 
843
- df_cluster = hierarchical_clustering_with_plotly(df_clean, linkage_method)
844
-
845
- st.subheader("Cluster Table")
846
- st.dataframe(df_clean)
847
-
848
- elif main_option == "Hypothesis test":
849
- st.header("Hypothesis Testing")
850
- hypothesis_option = st.selectbox("Please select the type of hypothesis test:", ["Z test", "T test", "Chi-Square test", "ANOVA test"])
851
-
852
- if hypothesis_option != "Z test":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
853
  st.info("This section of the program is under development.")
854
- else:
855
- uploaded_file = st.file_uploader("Please upload your Excel file for Z-Test", type=["xlsx", "xls"])
856
- if uploaded_file:
857
- result = analyze_z_test(uploaded_file)
858
- if result:
859
- st.success("Z-Test analysis completed successfully.")
860
-
861
- elif main_option in ["Machine Learning", "Coding"]:
862
- st.info("This section of the program is under development.")
 
544
 
545
  st.markdown('[Click to register a suggestion or comment](https://docs.google.com/forms/d/e/1FAIpQLScLyP7bBbqMfGdspjL7Ij64UZ6v2KjqjKNbm8gwEsgWsFs_Qg/viewform?usp=header)')
546
 
547
+ df = upload_and_select_dataframe()
 
548
 
549
+ try:
550
+ st.subheader("Displaying the first few rows of the DataFrame")
551
+ st.dataframe(df.head())
552
+
553
+ cols = edit_strings(df.columns)
554
+ cols = sorted(list(set(cols)))
555
+
556
+ main_option = st.selectbox("Please select an option:", ["Tabulation", "Funnel Analysis", "Segmentation Analysis", "Hypothesis test", "Machine Learning", "Coding"])
557
+
558
+ if main_option == "Tabulation":
559
+ st.header("Tabulation Analysis")
560
+
561
+ tabulation_option = st.selectbox("Please select the type of analysis:", ["Univariate", "Multivariate", "All"])
562
+
563
+ if tabulation_option == "All":
564
+
565
+ st.sidebar.header("Settings")
566
+
567
+ main_dict = {"single": [], "multi": [], "score": []}
568
+
569
+ st.sidebar.subheader("Main")
570
+ main_dict["single"] = st.sidebar.multiselect(
571
+ 'Main: Single answer questions',
572
+ cols,
573
+ default=[]
574
+ )
575
+
576
+ main_dict["multi"] = st.sidebar.multiselect(
577
+ 'Main: Multi answer questions',
578
+ cols,
579
+ default=[]
580
+ )
581
+
582
+ main_dict["score"] = st.sidebar.multiselect(
583
+ 'Main: Score answer questions',
584
+ cols,
585
+ default=[]
586
+ )
587
+
588
+ follow_dict = {"single": [], "multi": [], "score": []}
589
+
590
+ st.sidebar.subheader("Follow")
591
+ follow_dict["single"] = st.sidebar.multiselect(
592
+ 'Follow: Single answer questions',
593
+ cols,
594
+ default=[]
595
+ )
596
+
597
+ follow_dict["multi"] = st.sidebar.multiselect(
598
+ 'Follow: Multi answer questions',
599
+ cols,
600
+ default=[]
601
+ )
602
+
603
+ follow_dict["score"] = st.sidebar.multiselect(
604
+ 'Follow: Score answer questions',
605
+ cols,
606
+ default=[]
607
+ )
608
+
609
+ all_tabulation(df, main_dict, follow_dict)
610
+
611
+ elif tabulation_option == "Univariate":
612
+ uni_option = st.selectbox("Select the type of univariate analysis:", ["Multiple answer", "Single answer", "Score answer"])
613
+
614
+ if uni_option == "Single answer":
615
+ var = st.text_input("Please enter the name of the desired column:")
616
+ if var:
617
+ if var in df.columns:
618
+ result_df = single_answer(df[var])
619
+ st.subheader("Univariate Analysis Results")
620
+ st.dataframe(result_df)
621
+
622
+ fig = figo('Bar', result_df["Percentage"][:-1, ], title='Percentage Histogram', xlabel=var, ylabel='Percentage', colorscale='Plotly3')
623
+ st.plotly_chart(fig, use_container_width=True)
624
+ else:
625
+ st.error("The entered column was not found.")
626
+ elif uni_option == "Multiple answer":
627
+ var = st.text_input("Please enter the name of the desired column:")
628
+ if var:
629
+ matching_cols = [col for col in df.columns if is_matching_pattern(col, var)]
630
+ if matching_cols:
631
+ subset_df = df[matching_cols]
632
+ result_df = multi_answer(subset_df)
633
+
634
+ st.subheader("Multiple Answer Analysis Results")
635
+ st.dataframe(result_df)
636
 
637
+ fig = figo('Bar', result_df["Percentage"][:-1], title='Percentage Histogram', xlabel=var, ylabel='Percentage', colorscale='Plotly3')
638
+ st.plotly_chart(fig, use_container_width=True)
639
+ else:
640
+ st.error("No columns matching the entered pattern were found.")
641
+
642
+ elif uni_option == "Score answer":
643
+ var = st.text_input("Please enter the name of the desired column:")
644
+ if var:
645
+ subset_df = df[var]
646
+ result_df = score_answer(subset_df)
647
+
648
+ st.subheader("Score Answer Analysis Results")
649
  st.dataframe(result_df)
650
 
651
+ fig = figo('Bar', result_df["Percentage"][:-2], title='Percentage Histogram', xlabel=var, ylabel='Percentage', colorscale='Plotly3')
652
  st.plotly_chart(fig, use_container_width=True)
653
  else:
654
  st.error("No columns matching the entered pattern were found.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
655
 
656
+ elif tabulation_option == "Multivariate":
657
+ st.subheader("Multivariate Analysis")
658
+ var1 = st.text_input("Please enter the name of the first column:")
659
+ var2 = st.text_input("Please enter the name of the second column:")
660
+
661
+ if var1 and var2:
662
+ type1 = st.selectbox("Select the type of analysis for the first column:", ["Multiple answer", "Single answer"], key='type1')
663
+ type2 = st.selectbox("Select the type of analysis for the second column:", ["Multiple answer", "Single answer", "Score answer"], key='type2')
664
+
665
+ if type1 == "Single answer" and type2 == "Single answer":
666
+ percentile_df, frequency_df = two_variable_ss(df[[var1, var2]], var1, var2)
667
  st.subheader("Percentage Table")
668
  st.write(z_test_data(percentile_df))
669
+
670
  st.subheader("Frequency Table")
671
  st.dataframe(frequency_df)
672
+
673
  row, col = df.shape
674
  fig = figo('Scatter', percentile_df.iloc[:-1,:], title='Percentage Scatter plot', width=(col*5)+5, height=(row*25) + 10)
675
  st.plotly_chart(fig, use_container_width=True)
676
+
677
+ elif type1 == "Single answer" and type2 == "Multiple answer":
678
+ matching_cols = [col for col in df.columns if is_matching_pattern(col, var2)]
679
+ if matching_cols:
680
+ percentile_df, frequency_df = two_variable_sm(df[[var1] + matching_cols], var1, matching_cols)
681
+ st.subheader("Percentage Table")
682
+ st.write(z_test_data(percentile_df))
683
+
684
+ st.subheader("Frequency Table")
685
+ st.dataframe(frequency_df)
686
+
687
+ row, col = df.shape
688
+ fig = figo('Scatter', percentile_df.iloc[:-1,:], title='Percentage Scatter plot', width=(col*5)+5, height=(row*25) + 10)
689
+ st.plotly_chart(fig, use_container_width=True)
690
+
691
+ else:
692
+ st.error("No columns matching the entered pattern were found.")
693
+
694
+ elif type1 == "Multiple answer" and type2 == "Multiple answer":
695
+ matching_cols1 = [col for col in df.columns if is_matching_pattern(col, var1)]
696
+ matching_cols2 = [col for col in df.columns if is_matching_pattern(col, var2)]
697
+ if matching_cols1 and matching_cols2:
698
+ percentile_df, frequency_df = two_variable_mm(df[matching_cols1 + matching_cols2], matching_cols1, matching_cols2)
699
+ st.subheader("Percentage Table")
700
+ st.write(z_test_data(percentile_df))
701
+
702
+ st.subheader("Frequency Table")
703
+ st.dataframe(frequency_df)
704
+
705
+ row, col = df.shape
706
+ fig = figo('Scatter', percentile_df.iloc[:-1,:], title='Percentage Scatter plot', width=(col*5)+5, height=(row*25) + 10)
707
+ st.plotly_chart(fig, use_container_width=True)
708
+
709
+ elif type1 == "Single answer" and type2 == "Score answer":
710
+
711
+ mean_df = two_variable_ssc(df[[var1, var2]], var1, var2)
712
  st.subheader("Mean Table")
713
  st.write(t_test_data(mean_df))
714
+
715
  row, col = df.shape
716
  fig = figo('Bar', mean_df["Mean"][:-1], title='Mean Histogram', xlabel=var1, ylabel='Mean', colorscale='Plotly3')
717
+ st.plotly_chart(fig, use_container_width=True)
718
+
719
+
720
+ elif type1 == "Multiple answer" and type2 == "Score answer":
721
+ matching_cols1 = [col for col in df.columns if is_matching_pattern(col, var1)]
722
+ if matching_cols1:
723
+ mean_df = two_variable_msc(df[matching_cols1 + [var2]], matching_cols1, var2)
724
+ st.subheader("Mean Table")
725
+ st.write(t_test_data(mean_df))
726
+
727
+ row, col = df.shape
728
+ fig = figo('Bar', mean_df["Mean"][:-1], title='Mean Histogram', xlabel=var1, ylabel='Mean', colorscale='Plotly3')
729
+ st.plotly_chart(fig, use_container_width=True)
730
+ else:
731
+ st.info("This section of the program is under development.")
732
+
733
+ elif main_option == "Funnel Analysis":
734
+ st.header("Funnel")
735
+
736
+ st.sidebar.header("Funnel Settings")
737
+ single_list = st.sidebar.multiselect(
738
+ 'Single answer questions',
739
+ cols,
740
+ default=[]
741
+ )
742
+
743
+ multi_list = st.sidebar.multiselect(
744
+ 'Multi answer questions',
745
+ cols,
746
+ default=[]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
747
  )
748
+ selected_dict = {}
749
+
750
+ for option in single_list:
751
+ selected_dict[option] = "Single"
752
+ for option in multi_list:
753
+ selected_dict[option] = "Multi"
754
+
755
+ funnel_frequency, funnel_percentage = funnel(df, selected_dict)
756
+ st.subheader("Percentage Table")
757
+ st.dataframe(funnel_percentage)
758
+
759
+ st.subheader("Frequency Table")
760
+ st.dataframe(funnel_frequency)
761
+
762
+ st.sidebar.header("Chart Settings")
763
+ bar_columns = st.sidebar.multiselect('Which columns should be displayed as bar charts?', sorted(funnel_percentage.columns))
764
+ line_columns = st.sidebar.multiselect('Which columns should be displayed as line charts?', sorted(funnel_percentage.columns))
765
 
766
+ funnel_percentage_cleaned = funnel_percentage.dropna(axis=0, how='all')
767
+
768
+ fig = go.Figure()
769
+
770
+ # Define modern and diverse color palette
771
+ modern_colors = [
772
+ "#FF6F61", "#6B5B95", "#88B04B", "#F7CAC9", "#92A8D1",
773
+ "#955251", "#B565A7", "#009B77", "#DD4124", "#45B8AC"
774
+ ]
775
+
776
+ # Add Bar traces with transparency and custom colors
777
+ for idx, col in enumerate(bar_columns):
778
+ funnel_percentage_col = funnel_percentage_cleaned[col]
779
+ fig.add_trace(
780
+ go.Bar(
781
+ x=funnel_percentage_cleaned.index,
782
+ y=funnel_percentage_col,
783
+ name=col,
784
+ marker_color=modern_colors[idx % len(modern_colors)], # Cycle through colors
785
+ opacity=0.8 # Set transparency
786
+ )
787
+ )
788
+
789
+ # Add Line traces with transparency and custom colors
790
+ for idx, col in enumerate(line_columns):
791
+ funnel_percentage_col = funnel_percentage_cleaned[col]
792
+ fig.add_trace(
793
+ go.Scatter(
794
+ x=funnel_percentage_cleaned.index,
795
+ y=funnel_percentage_col,
796
+ mode='lines',
797
+ name=col,
798
+ line=dict(color=modern_colors[(idx + len(bar_columns)) % len(modern_colors)]), # Cycle through colors
799
+ opacity=0.8 # Set transparency
800
+ )
801
  )
802
+
803
+ fig.update_layout(
804
+ title="Combined Bar and Line Chart",
805
+ xaxis_title="Brands",
806
+ yaxis_title="Percentage",
807
+ template="plotly_dark",
808
+ barmode="group",
809
+ xaxis=dict(tickmode='linear')
810
  )
811
+
812
+ st.plotly_chart(fig)
 
 
 
 
 
 
 
813
 
814
+ elif main_option == "Segmentation Analysis":
815
+ st.header("Segmentation Analysis")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
816
 
817
+ st.sidebar.header("Selection of questions")
818
+ single_list = st.sidebar.multiselect(
819
+ 'Single answer questions',
820
+ cols,
821
+ default=[]
822
+ )
823
+
824
+ multi_list = st.sidebar.multiselect(
825
+ 'Multi answer questions',
826
+ cols,
827
+ default=[]
828
+ )
829
+
830
+ score_list = st.sidebar.multiselect(
831
+ 'Score answer questions',
832
+ cols,
833
+ default=[]
834
+ )
835
+
836
+ matching_cols1 = []
837
+ for i in multi_list:
838
+ matching_cols1 += [col for col in df.columns if is_matching_pattern(col, i)]
839
+
840
+ df_clean = process_dataframe(df[single_list + matching_cols1])
841
+ st.subheader("Selected Table")
842
+ st.dataframe(df_clean)
843
+
844
+ linkage_method = st.sidebar.selectbox("Select the Linkage Method of Segmentation Analysis:", ['average', 'single', 'complete', 'weighted', 'centroid', 'median', 'ward'])
845
+
846
+ df_cluster = hierarchical_clustering_with_plotly(df_clean, linkage_method)
847
+
848
+ st.subheader("Cluster Table")
849
+ st.dataframe(df_clean)
850
+
851
+ elif main_option == "Hypothesis test":
852
+ st.header("Hypothesis Testing")
853
+ hypothesis_option = st.selectbox("Please select the type of hypothesis test:", ["Z test", "T test", "Chi-Square test", "ANOVA test"])
854
+
855
+ if hypothesis_option != "Z test":
856
+ st.info("This section of the program is under development.")
857
+ else:
858
+ uploaded_file = st.file_uploader("Please upload your Excel file for Z-Test", type=["xlsx", "xls"])
859
+ if uploaded_file:
860
+ result = analyze_z_test(uploaded_file)
861
+ if result:
862
+ st.success("Z-Test analysis completed successfully.")
863
+
864
+ elif main_option in ["Machine Learning", "Coding"]:
865
  st.info("This section of the program is under development.")
866
+
867
+ except Exception as e:
868
+ st.error(f"❌ Error: {e}")