JUNGU commited on
Commit
f7f3976
Β·
verified Β·
1 Parent(s): 5d3671b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -25
app.py CHANGED
@@ -106,10 +106,11 @@ def create_slicers(data):
106
  )
107
 
108
  def apply_slicers(data):
 
109
  for col, selected_values in st.session_state.slicers.items():
110
  if selected_values:
111
- data = data[data[col].isin(selected_values)]
112
- return data
113
 
114
  def plot_correlation_heatmap(data):
115
  corr = data[st.session_state.numeric_columns].corr()
@@ -150,43 +151,46 @@ def plot_scatter_with_regression(data, x_var, y_var):
150
  st.write(f"μƒκ΄€κ³„μˆ˜: {r_value:.4f}")
151
  st.write(f"p-value: {p_value:.4f}")
152
  st.write(f"ν‘œμ€€ 였차: {std_err:.4f}")
153
-
154
- def perform_analysis():
155
- st.header("탐색적 데이터 뢄석")
156
 
157
- # μŠ¬λΌμ΄μ„œ 생성 및 적용
158
- create_slicers(st.session_state.processed_data)
159
- filtered_data = apply_slicers(st.session_state.processed_data)
160
-
161
- # μš”μ•½ 톡계
162
- st.write("μš”μ•½ 톡계:")
163
- st.write(filtered_data.describe())
 
 
 
 
164
 
165
- # 상관관계 히트맡
166
- st.subheader("상관관계 히트맡")
167
- plot_correlation_heatmap(filtered_data)
168
-
169
- # μ‚¬μš©μžκ°€ μ„ νƒν•œ 두 λ³€μˆ˜μ— λŒ€ν•œ 산점도 및 νšŒκ·€ 뢄석
170
- st.subheader("두 λ³€μˆ˜ κ°„μ˜ 관계 뢄석")
171
- st.session_state.x_var = st.selectbox("XμΆ• λ³€μˆ˜ 선택", options=st.session_state.numeric_columns, key='x_var')
172
- st.session_state.y_var = st.selectbox("YμΆ• λ³€μˆ˜ 선택", options=[col for col in st.session_state.numeric_columns if col != st.session_state.x_var], key='y_var')
173
 
174
- if st.session_state.x_var and st.session_state.y_var:
175
- plot_scatter_with_regression(filtered_data, st.session_state.x_var, st.session_state.y_var)
176
 
177
- st.session_state.analysis_performed = True
 
 
178
 
179
  def main():
180
  st.title("μΈν„°λž™ν‹°λΈŒ EDA νˆ΄ν‚·")
181
 
182
  manage_session_state()
183
 
184
- if not st.session_state.data:
185
  data_input_method = st.radio("데이터 μž…λ ₯ 방법 선택:", ("파일 μ—…λ‘œλ“œ", "μˆ˜λ™ μž…λ ₯"), key="data_input_method")
186
 
187
  if data_input_method == "파일 μ—…λ‘œλ“œ":
188
  uploaded_file = st.file_uploader("CSV, XLS, λ˜λŠ” XLSX νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”", type=["csv", "xls", "xlsx"], key="file_uploader")
189
- if uploaded_file:
190
  st.session_state.data = load_data(uploaded_file)
191
  else:
192
  st.session_state.data = manual_data_entry()
 
106
  )
107
 
108
  def apply_slicers(data):
109
+ filtered_data = data.copy()
110
  for col, selected_values in st.session_state.slicers.items():
111
  if selected_values:
112
+ filtered_data = filtered_data[filtered_data[col].isin(selected_values)]
113
+ return filtered_data
114
 
115
  def plot_correlation_heatmap(data):
116
  corr = data[st.session_state.numeric_columns].corr()
 
151
  st.write(f"μƒκ΄€κ³„μˆ˜: {r_value:.4f}")
152
  st.write(f"p-value: {p_value:.4f}")
153
  st.write(f"ν‘œμ€€ 였차: {std_err:.4f}")
 
 
 
154
 
155
+ def perform_analysis():
156
+ if st.session_state.processed_data is not None and not st.session_state.processed_data.empty:
157
+ st.header("탐색적 데이터 뢄석")
158
+
159
+ # μŠ¬λΌμ΄μ„œ 생성 및 적용
160
+ create_slicers(st.session_state.processed_data)
161
+ filtered_data = apply_slicers(st.session_state.processed_data)
162
+
163
+ # μš”μ•½ 톡계
164
+ st.write("μš”μ•½ 톡계:")
165
+ st.write(filtered_data.describe())
166
 
167
+ # 상관관계 히트맡
168
+ st.subheader("상관관계 히트맡")
169
+ plot_correlation_heatmap(filtered_data)
170
+
171
+ # μ‚¬μš©μžκ°€ μ„ νƒν•œ 두 λ³€μˆ˜μ— λŒ€ν•œ 산점도 및 νšŒκ·€ 뢄석
172
+ st.subheader("두 λ³€μˆ˜ κ°„μ˜ 관계 뢄석")
173
+ st.session_state.x_var = st.selectbox("XμΆ• λ³€μˆ˜ 선택", options=st.session_state.numeric_columns, key='x_var')
174
+ st.session_state.y_var = st.selectbox("YμΆ• λ³€μˆ˜ 선택", options=[col for col in st.session_state.numeric_columns if col != st.session_state.x_var], key='y_var')
175
 
176
+ if st.session_state.x_var and st.session_state.y_var:
177
+ plot_scatter_with_regression(filtered_data, st.session_state.x_var, st.session_state.y_var)
178
 
179
+ st.session_state.analysis_performed = True
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()