JUNGU commited on
Commit
38cbba4
Β·
verified Β·
1 Parent(s): f7f3976

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -12
app.py CHANGED
@@ -180,29 +180,72 @@ def perform_analysis():
180
  else:
181
  st.warning("뢄석할 데이터가 μ—†μŠ΅λ‹ˆλ‹€. 데이터λ₯Ό λ¨Όμ € λ‘œλ“œν•˜κ³  μ „μ²˜λ¦¬ν•΄μ£Όμ„Έμš”.")
182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  def main():
184
  st.title("μΈν„°λž™ν‹°λΈŒ EDA νˆ΄ν‚·")
185
 
186
  manage_session_state()
187
 
188
- if st.session_state.data is None:
189
- data_input_method = st.radio("데이터 μž…λ ₯ 방법 선택:", ("파일 μ—…λ‘œλ“œ", "μˆ˜λ™ μž…λ ₯"), key="data_input_method")
190
-
191
- if data_input_method == "파일 μ—…λ‘œλ“œ":
192
- uploaded_file = st.file_uploader("CSV, XLS, λ˜λŠ” XLSX νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”", type=["csv", "xls", "xlsx"], key="file_uploader")
193
- if uploaded_file is not None:
194
- st.session_state.data = load_data(uploaded_file)
195
- else:
196
- st.session_state.data = manual_data_entry()
197
-
198
  if st.session_state.data is not None:
199
  st.subheader("데이터 미리보기 및 μˆ˜μ •")
200
  st.write("데이터λ₯Ό ν™•μΈν•˜κ³  ν•„μš”ν•œ 경우 μˆ˜μ •ν•˜μ„Έμš”:")
201
  edited_data = st.data_editor(st.session_state.data, num_rows="dynamic", key="data_editor")
202
 
203
- if st.button("데이터 뢄석 μ‹œμž‘", key="start_analysis") or st.session_state.analysis_performed:
204
- if not st.session_state.analysis_performed:
205
  st.session_state.processed_data = preprocess_data(edited_data)
 
206
  perform_analysis()
207
 
208
  if __name__ == "__main__":
 
180
  else:
181
  st.warning("뢄석할 데이터가 μ—†μŠ΅λ‹ˆλ‹€. 데이터λ₯Ό λ¨Όμ € λ‘œλ“œν•˜κ³  μ „μ²˜λ¦¬ν•΄μ£Όμ„Έμš”.")
182
 
183
+
184
+ # state μœ μ§€ν•˜λ„λ‘ μΆ”κ°€
185
+
186
+ def update_filtered_data():
187
+ st.session_state.filtered_data = apply_slicers(st.session_state.processed_data)
188
+
189
+ def create_slicers(data):
190
+ for col in st.session_state.categorical_columns:
191
+ if data[col].nunique() <= 10:
192
+ st.session_state.slicers[col] = st.multiselect(
193
+ f"{col} 선택",
194
+ options=sorted(data[col].unique()),
195
+ default=sorted(data[col].unique()),
196
+ key=f"slicer_{col}",
197
+ on_change=update_filtered_data
198
+ )
199
+
200
+ def apply_slicers(data):
201
+ filtered_data = data.copy()
202
+ for col, selected_values in st.session_state.slicers.items():
203
+ if selected_values:
204
+ filtered_data = filtered_data[filtered_data[col].isin(selected_values)]
205
+ return filtered_data
206
+
207
+ def perform_analysis():
208
+ if 'filtered_data' not in st.session_state or st.session_state.filtered_data is None:
209
+ st.session_state.filtered_data = st.session_state.processed_data.copy()
210
+
211
+ st.header("탐색적 데이터 뢄석")
212
+
213
+ # μŠ¬λΌμ΄μ„œ 생성
214
+ create_slicers(st.session_state.processed_data)
215
+
216
+ # μš”μ•½ 톡계
217
+ st.write("μš”μ•½ 톡계:")
218
+ st.write(st.session_state.filtered_data.describe())
219
+
220
+ # 상관관계 히트맡
221
+ st.subheader("상관관계 히트맡")
222
+ plot_correlation_heatmap(st.session_state.filtered_data)
223
+
224
+ # μ‚¬μš©μžκ°€ μ„ νƒν•œ 두 λ³€μˆ˜μ— λŒ€ν•œ 산점도 및 νšŒκ·€ 뢄석
225
+ st.subheader("두 λ³€μˆ˜ κ°„μ˜ 관계 뢄석")
226
+ x_var = st.selectbox("XμΆ• λ³€μˆ˜ 선택", options=st.session_state.numeric_columns, key='x_var')
227
+ y_var = st.selectbox("YμΆ• λ³€μˆ˜ 선택", options=[col for col in st.session_state.numeric_columns if col != x_var], key='y_var')
228
+
229
+ if x_var and y_var:
230
+ plot_scatter_with_regression(st.session_state.filtered_data, x_var, y_var)
231
+
232
  def main():
233
  st.title("μΈν„°λž™ν‹°λΈŒ EDA νˆ΄ν‚·")
234
 
235
  manage_session_state()
236
 
237
+ if 'data' not in st.session_state or st.session_state.data is None:
238
+ # ... (데이터 λ‘œλ“œ λΆ€λΆ„)
239
+
 
 
 
 
 
 
 
240
  if st.session_state.data is not None:
241
  st.subheader("데이터 미리보기 및 μˆ˜μ •")
242
  st.write("데이터λ₯Ό ν™•μΈν•˜κ³  ν•„μš”ν•œ 경우 μˆ˜μ •ν•˜μ„Έμš”:")
243
  edited_data = st.data_editor(st.session_state.data, num_rows="dynamic", key="data_editor")
244
 
245
+ if st.button("데이터 뢄석 μ‹œμž‘", key="start_analysis") or ('analysis_performed' in st.session_state and st.session_state.analysis_performed):
246
+ if 'analysis_performed' not in st.session_state or not st.session_state.analysis_performed:
247
  st.session_state.processed_data = preprocess_data(edited_data)
248
+ st.session_state.analysis_performed = True
249
  perform_analysis()
250
 
251
  if __name__ == "__main__":