nlpblogs commited on
Commit
22dc405
·
verified ·
1 Parent(s): b080639

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -97,18 +97,27 @@ if upload_file is not None:
97
  else:
98
  new_columns = [f'column_{i+1}' for i in range(len(df.columns))]
99
  df.columns = new_columns
100
-
101
  st.dataframe(df, key="csv_dataframe")
102
- fig = px.treemap(df, path=[px.Constant("all"), 'column_1', 'column_3'],
103
- color='column_2')
104
- fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
105
- st.subheader("Tree map", divider = "red")
106
- st.plotly_chart(fig)
 
 
 
 
 
 
 
 
 
 
107
 
108
 
109
- st.write("_number of rows_", df.shape[0])
110
- st.write("_number of columns_", df.shape[1])
111
- st.session_state.df = df
112
  except pd.errors.ParserError:
113
  st.error("Error: The CSV file is not readable or is incorrectly formatted.")
114
  st.stop()
 
97
  else:
98
  new_columns = [f'column_{i+1}' for i in range(len(df.columns))]
99
  df.columns = new_columns
 
100
  st.dataframe(df, key="csv_dataframe")
101
+ all_columns = df.columns.tolist()
102
+ st.subheader("Select columns for the Tree Map", divider="blue")
103
+ parent_column = st.selectbox("Select the parent column:", all_columns)
104
+ value_column = st.selectbox("Select the value column:", all_columns)
105
+ color_column = st.selectbox("Select the color column (optional):", ["None"] + all_columns)
106
+ if parent_column and value_column:
107
+ path_columns = [px.Constant("all"), parent_column]
108
+ color_param = value_column if color_column == "None" else color_column
109
+ fig = px.treemap(df,
110
+ path=path_columns,
111
+ values=value_column,
112
+ color=color_param)
113
+ fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
114
+ st.subheader("Tree map", divider="red")
115
+ st.plotly_chart(fig)
116
 
117
 
118
+ st.write("_number of rows_", df.shape[0])
119
+ st.write("_number of columns_", df.shape[1])
120
+ st.session_state.df = df
121
  except pd.errors.ParserError:
122
  st.error("Error: The CSV file is not readable or is incorrectly formatted.")
123
  st.stop()