nlpblogs commited on
Commit
886f0ee
·
verified ·
1 Parent(s): fd943ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -29,9 +29,7 @@ expander.write('''
29
  To change the app's background color to white or black, click the three-dot menu on the right-hand side of your app, go to Settings and then Choose app theme, colors and fonts.
30
 
31
  **File Handling and Errors:**
32
- The app may provide an inaccurate answer, if the information is missing from the relevant cell.
33
-
34
- The app may display an error message if your file has errors or date values.
35
 
36
  For any errors or inquiries, please contact us at [email protected]
37
 
@@ -52,7 +50,6 @@ max_attempts = 5
52
 
53
 
54
  upload_file = st.file_uploader("Upload your file. Accepted file formats include: .csv, .xlsx", type=['csv', 'xlsx'])
55
-
56
  if upload_file is not None:
57
  file_extension = upload_file.name.split('.')[-1].lower()
58
  try:
@@ -64,34 +61,38 @@ if upload_file is not None:
64
  st.warning("Unsupported file type.")
65
  st.stop()
66
 
 
 
 
 
 
 
67
  if df_original.isnull().values.any():
68
  st.error("Error: The file contains missing values.")
69
  st.stop()
70
  else:
71
- st.session_state.df_original = df_original
72
 
73
  all_columns = df_original.columns.tolist()
74
  st.subheader("Select columns from your data to visualize it in a tree map", divider="blue")
75
  parent_column = st.selectbox("Select the parent column:", all_columns)
76
  value_column = st.selectbox("Select the value column:", all_columns)
77
-
78
  if parent_column and value_column:
79
  if parent_column == value_column:
80
  st.warning("Warning: You have selected the same column for both the parent and value column. Please select two different columns from your data.")
81
  else:
82
- df_treemap = df_original.copy()
 
83
  path_columns = [px.Constant("all"), parent_column, value_column]
84
  fig = px.treemap(df_treemap,
85
  path=path_columns)
86
  fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
87
  st.subheader("Tree map", divider="blue")
88
  st.plotly_chart(fig)
89
-
90
  st.subheader("Uploaded File", divider="blue")
91
  st.dataframe(df_original, key="uploaded_dataframe")
92
  st.write(f"_Number of rows_: {df_original.shape[0]}")
93
  st.write(f"_Number of columns_: {df_original.shape[1]}")
94
-
95
  except pd.errors.ParserError:
96
  st.error("Error: The CSV file is not readable or is incorrectly formatted.")
97
  st.stop()
@@ -104,8 +105,9 @@ if upload_file is not None:
104
  except Exception as e:
105
  st.error(f"An unexpected error occurred: {e}")
106
  st.stop()
107
-
108
  st.divider()
 
 
109
 
110
 
111
  def clear_question():
 
29
  To change the app's background color to white or black, click the three-dot menu on the right-hand side of your app, go to Settings and then Choose app theme, colors and fonts.
30
 
31
  **File Handling and Errors:**
32
+ (a) The app may provide an inaccurate answer, if the information is missing from the relevant cell. (b) The app may display an error message if your file has errors or date values.
 
 
33
 
34
  For any errors or inquiries, please contact us at [email protected]
35
 
 
50
 
51
 
52
  upload_file = st.file_uploader("Upload your file. Accepted file formats include: .csv, .xlsx", type=['csv', 'xlsx'])
 
53
  if upload_file is not None:
54
  file_extension = upload_file.name.split('.')[-1].lower()
55
  try:
 
61
  st.warning("Unsupported file type.")
62
  st.stop()
63
 
64
+ # Convert float columns to integers if they contain whole numbers
65
+ for col in df_original.columns:
66
+ if df_original[col].dtype == 'float64':
67
+ if all(df_original[col] == df_original[col].astype(int)):
68
+ df_original[col] = df_original[col].astype(int)
69
+
70
  if df_original.isnull().values.any():
71
  st.error("Error: The file contains missing values.")
72
  st.stop()
73
  else:
74
+ st.session_state.df_original = df_original
75
 
76
  all_columns = df_original.columns.tolist()
77
  st.subheader("Select columns from your data to visualize it in a tree map", divider="blue")
78
  parent_column = st.selectbox("Select the parent column:", all_columns)
79
  value_column = st.selectbox("Select the value column:", all_columns)
 
80
  if parent_column and value_column:
81
  if parent_column == value_column:
82
  st.warning("Warning: You have selected the same column for both the parent and value column. Please select two different columns from your data.")
83
  else:
84
+ df_treemap = df_original.copy()
85
+
86
  path_columns = [px.Constant("all"), parent_column, value_column]
87
  fig = px.treemap(df_treemap,
88
  path=path_columns)
89
  fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
90
  st.subheader("Tree map", divider="blue")
91
  st.plotly_chart(fig)
 
92
  st.subheader("Uploaded File", divider="blue")
93
  st.dataframe(df_original, key="uploaded_dataframe")
94
  st.write(f"_Number of rows_: {df_original.shape[0]}")
95
  st.write(f"_Number of columns_: {df_original.shape[1]}")
 
96
  except pd.errors.ParserError:
97
  st.error("Error: The CSV file is not readable or is incorrectly formatted.")
98
  st.stop()
 
105
  except Exception as e:
106
  st.error(f"An unexpected error occurred: {e}")
107
  st.stop()
 
108
  st.divider()
109
+
110
+
111
 
112
 
113
  def clear_question():