berangerthomas commited on
Commit
62ca211
·
1 Parent(s): 774bf05

Add "sunburst chart" to "Analyze" page

Browse files
Files changed (1) hide show
  1. sections/analyze.py +26 -1
sections/analyze.py CHANGED
@@ -30,7 +30,7 @@ if not datetime_columns:
30
  pass
31
 
32
  # Chart type options
33
- chart_options = ["Pie Chart", "Histogram"]
34
  if datetime_columns:
35
  chart_options.append("Time Series")
36
 
@@ -62,6 +62,31 @@ if chart_type == "Pie Chart":
62
  st.write("Value distribution:")
63
  st.write(data[selected_column].value_counts())
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  elif chart_type == "Histogram":
66
  st.header("Histogram")
67
 
 
30
  pass
31
 
32
  # Chart type options
33
+ chart_options = ["Pie Chart", "Sunburst Chart", "Histogram"]
34
  if datetime_columns:
35
  chart_options.append("Time Series")
36
 
 
62
  st.write("Value distribution:")
63
  st.write(data[selected_column].value_counts())
64
 
65
+ elif chart_type == "Sunburst Chart":
66
+ st.header("Sunburst Chart")
67
+
68
+ selected_columns = st.sidebar.multiselect(
69
+ "Select one or more categorical variables:",
70
+ categorical_columns,
71
+ default=categorical_columns[:1],
72
+ )
73
+
74
+ if not selected_columns:
75
+ st.warning("Please select at least one variable.")
76
+ st.stop()
77
+
78
+ fig = px.sunburst(
79
+ data,
80
+ path=selected_columns,
81
+ title="Sunburst Chart",
82
+ )
83
+ fig.update_traces(textinfo="label+percent parent")
84
+ st.plotly_chart(fig)
85
+
86
+ st.write("Value distribution:")
87
+ group_counts = data.groupby(selected_columns).size().reset_index(name="Count")
88
+ st.write(group_counts)
89
+
90
  elif chart_type == "Histogram":
91
  st.header("Histogram")
92