AMKhakbaz commited on
Commit
a52511a
·
verified ·
1 Parent(s): 7f5a293

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -20
app.py CHANGED
@@ -11,6 +11,17 @@ def sorting(df):
11
 
12
  return df
13
 
 
 
 
 
 
 
 
 
 
 
 
14
  def figo(plot_type, df, title, xlabel=None, ylabel=None, legend_title=None, colorscale='Plotly3', width=800, height=600):
15
  if plot_type == "Scatter":
16
  fig = go.Figure()
@@ -538,38 +549,58 @@ elif main_option == "Funnel":
538
  uploaded_file = st.file_uploader("Please upload your Excel file", type=["xlsx", "xls"])
539
  if uploaded_file:
540
  try:
541
- #df = pd.read_excel(uploaded_file)
542
- #st.subheader("Displaying the first few rows of the DataFrame")
 
543
 
544
- data = {
545
- 'A': [10, 20, 30, np.nan, np.nan],
546
- 'B': [5, 10, 15, 20, 25],
547
- 'C': [np.nan, 100, 150, 200, 250],
548
- 'D': [100, np.nan, 200, 300, 400]
549
- }
550
- df = pd.DataFrame(data)
551
 
552
- st.dataframe(df.head())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
553
  st.sidebar.header("Chart Settings")
554
- bar_columns = st.sidebar.multiselect('Which columns should be displayed as bar charts?', df.columns)
555
- line_columns = st.sidebar.multiselect('Which columns should be displayed as line charts?', df.columns)
556
 
557
- df_cleaned = df.dropna(axis=0, how='all')
558
 
559
  fig = go.Figure()
560
 
561
  for col in bar_columns:
562
- df_col = df_cleaned[col]
563
- fig.add_trace(go.Bar(x=df_cleaned.index, y=df_col, name=col))
564
 
565
  for col in line_columns:
566
- df_col = df_cleaned[col]
567
- fig.add_trace(go.Scatter(x=df_cleaned.index, y=df_col, mode='lines', name=col))
568
 
569
  fig.update_layout(
570
  title="Combined Bar and Line Chart",
571
- xaxis_title="Rows",
572
- yaxis_title="Value",
573
  template="plotly_dark",
574
  barmode="group",
575
  xaxis=dict(tickmode='linear')
@@ -577,7 +608,6 @@ elif main_option == "Funnel":
577
 
578
  st.plotly_chart(fig)
579
 
580
-
581
  except Exception as e:
582
  st.error(f"❌ Error reading the Excel file: {e}")
583
 
 
11
 
12
  return df
13
 
14
+ def edit_strings(string_list):
15
+ edited_list = []
16
+ for string in string_list:
17
+ if "_" in string:
18
+ last_underscore_index = string.rfind("_")
19
+ edited_string = string[:last_underscore_index]
20
+ edited_list.append(edited_string)
21
+ else:
22
+ edited_list.append(string)
23
+ return edited_list
24
+
25
  def figo(plot_type, df, title, xlabel=None, ylabel=None, legend_title=None, colorscale='Plotly3', width=800, height=600):
26
  if plot_type == "Scatter":
27
  fig = go.Figure()
 
549
  uploaded_file = st.file_uploader("Please upload your Excel file", type=["xlsx", "xls"])
550
  if uploaded_file:
551
  try:
552
+ df = pd.read_excel(uploaded_file)
553
+ st.subheader("Displaying the first few rows of the DataFrame")
554
+ st.dataframe(df.head())
555
 
556
+ cols = edit_strings(list(df.columns))
 
 
 
 
 
 
557
 
558
+ st.sidebar.header("Funnul Settings")
559
+ single_answer = st.sidebar.multiselect(
560
+ 'Select a single option (Single answer)',
561
+ cols,
562
+ default=[]
563
+ )
564
+
565
+ multi_answer = st.sidebar.multiselect(
566
+ 'Select multiple options (Multi answer)',
567
+ cols,
568
+ default=[]
569
+ )
570
+ selected_dict = {}
571
+
572
+ for option in single_answer:
573
+ selected_dict[option] = "Single"
574
+ for option in multi_answer:
575
+ selected_dict[option] = "Multi"
576
+
577
+ funnel_frequency, funnel_percentage = funnel(df, selected_dict)
578
+ st.subheader("Percentage Table")
579
+ st.dataframe(funnel_percentage)
580
+
581
+ st.subheader("Frequency Table")
582
+ st.dataframe(funnel_frequency)
583
+
584
  st.sidebar.header("Chart Settings")
585
+ bar_columns = st.sidebar.multiselect('Which columns should be displayed as bar charts?', funnel_percentage.columns)
586
+ line_columns = st.sidebar.multiselect('Which columns should be displayed as line charts?', funnel_percentage.columns)
587
 
588
+ funnel_percentage_cleaned = funnel_percentage.dropna(axis=0, how='all')
589
 
590
  fig = go.Figure()
591
 
592
  for col in bar_columns:
593
+ funnel_percentage_col = funnel_percentage_cleaned[col]
594
+ fig.add_trace(go.Bar(x=funnel_percentage_cleaned.index, y=funnel_percentage_col, name=col))
595
 
596
  for col in line_columns:
597
+ funnel_percentage_col = funnel_percentage_cleaned[col]
598
+ fig.add_trace(go.Scatter(x=funnel_percentage_cleaned.index, y=funnel_percentage_col, mode='lines', name=col))
599
 
600
  fig.update_layout(
601
  title="Combined Bar and Line Chart",
602
+ xaxis_title="Brands",
603
+ yaxis_title="Percentage",
604
  template="plotly_dark",
605
  barmode="group",
606
  xaxis=dict(tickmode='linear')
 
608
 
609
  st.plotly_chart(fig)
610
 
 
611
  except Exception as e:
612
  st.error(f"❌ Error reading the Excel file: {e}")
613