Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
542 |
-
|
|
|
543 |
|
544 |
-
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
553 |
st.sidebar.header("Chart Settings")
|
554 |
-
bar_columns = st.sidebar.multiselect('Which columns should be displayed as bar charts?',
|
555 |
-
line_columns = st.sidebar.multiselect('Which columns should be displayed as line charts?',
|
556 |
|
557 |
-
|
558 |
|
559 |
fig = go.Figure()
|
560 |
|
561 |
for col in bar_columns:
|
562 |
-
|
563 |
-
fig.add_trace(go.Bar(x=
|
564 |
|
565 |
for col in line_columns:
|
566 |
-
|
567 |
-
fig.add_trace(go.Scatter(x=
|
568 |
|
569 |
fig.update_layout(
|
570 |
title="Combined Bar and Line Chart",
|
571 |
-
xaxis_title="
|
572 |
-
yaxis_title="
|
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 |
|