Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -361,13 +361,15 @@ elif app_mode == "Data Cleaning":
|
|
361 |
st.warning("Please upload data first")
|
362 |
st.stop()
|
363 |
|
364 |
-
|
|
|
365 |
|
366 |
-
# Initialize session state
|
367 |
if 'data_versions' not in st.session_state:
|
368 |
st.session_state.data_versions = [st.session_state.raw_data.copy()]
|
369 |
-
if 'cleaned_data' not in st.session_state:
|
370 |
st.session_state.cleaned_data = st.session_state.raw_data.copy()
|
|
|
371 |
|
372 |
# --------------------------
|
373 |
# Data Health Dashboard
|
@@ -397,7 +399,6 @@ elif app_mode == "Data Cleaning":
|
|
397 |
st.session_state.data_versions.pop() # Remove current version
|
398 |
st.session_state.cleaned_data = st.session_state.data_versions[-1].copy() # Set data
|
399 |
st.success("Last action undone!")
|
400 |
-
st.rerun() #Force re-run after undo
|
401 |
|
402 |
# --------------------------
|
403 |
# Missing Value Handling
|
@@ -438,8 +439,7 @@ elif app_mode == "Data Cleaning":
|
|
438 |
new_df[cols] = new_df[cols].bfill()
|
439 |
|
440 |
update_cleaned_data(new_df)
|
441 |
-
|
442 |
-
|
443 |
except Exception as e:
|
444 |
st.error(f"Error: {str(e)}")
|
445 |
else:
|
@@ -480,7 +480,6 @@ elif app_mode == "Data Cleaning":
|
|
480 |
new_df[col_to_convert] = pd.to_datetime(new_df[col_to_convert], format=date_format, errors='coerce')
|
481 |
|
482 |
update_cleaned_data(new_df)
|
483 |
-
st.rerun() #Force re-run after apply
|
484 |
except Exception as e:
|
485 |
st.error(f"Error: {str(e)}")
|
486 |
|
@@ -496,7 +495,6 @@ elif app_mode == "Data Cleaning":
|
|
496 |
new_df = df.copy()
|
497 |
new_df = new_df.drop(columns=columns_to_drop)
|
498 |
update_cleaned_data(new_df)
|
499 |
-
st.rerun() #Force re-run after apply
|
500 |
|
501 |
# --------------------------
|
502 |
# Label Encoding
|
@@ -513,7 +511,6 @@ elif app_mode == "Data Cleaning":
|
|
513 |
new_df[col] = le.fit_transform(new_df[col].astype(str))
|
514 |
label_encoders[col] = le
|
515 |
update_cleaned_data(new_df)
|
516 |
-
st.rerun() #Force re-run after apply
|
517 |
|
518 |
# --------------------------
|
519 |
# StandardScaler
|
@@ -528,7 +525,6 @@ elif app_mode == "Data Cleaning":
|
|
528 |
scaler = StandardScaler()
|
529 |
new_df[scale_cols] = scaler.fit_transform(new_df[scale_cols])
|
530 |
update_cleaned_data(new_df)
|
531 |
-
st.rerun()#Force re-run after apply
|
532 |
except Exception as e:
|
533 |
st.error(f"Error: {str(e)}")
|
534 |
|
@@ -562,7 +558,6 @@ elif app_mode == "Data Cleaning":
|
|
562 |
text_cols = new_df.select_dtypes(include='object').columns
|
563 |
new_df[text_cols] = new_df[text_cols].apply(lambda x: x.str.strip())
|
564 |
update_cleaned_data(new_df)
|
565 |
-
st.rerun() #Force re-run after apply
|
566 |
|
567 |
# --------------------------
|
568 |
# Cleaned Data Preview
|
@@ -570,10 +565,11 @@ elif app_mode == "Data Cleaning":
|
|
570 |
if st.session_state.get("cleaned_data") is not None:
|
571 |
enhance_section_title("Cleaned Data Preview", "✨")
|
572 |
with st.expander("✨ Cleaned Data Preview", expanded=True):
|
573 |
-
st.dataframe(
|
574 |
-
|
575 |
-
|
576 |
-
|
|
|
577 |
|
578 |
# --------------------------
|
579 |
# EDA
|
|
|
361 |
st.warning("Please upload data first")
|
362 |
st.stop()
|
363 |
|
364 |
+
# Use cleaned_data as the base dataframe
|
365 |
+
df = st.session_state.cleaned_data.copy() # Changed line
|
366 |
|
367 |
+
# Initialize session state
|
368 |
if 'data_versions' not in st.session_state:
|
369 |
st.session_state.data_versions = [st.session_state.raw_data.copy()]
|
370 |
+
if 'cleaned_data' not in st.session_state:
|
371 |
st.session_state.cleaned_data = st.session_state.raw_data.copy()
|
372 |
+
st.dataframe(st.session_state.cleaned_data.head(), use_container_width=True, height=300)
|
373 |
|
374 |
# --------------------------
|
375 |
# Data Health Dashboard
|
|
|
399 |
st.session_state.data_versions.pop() # Remove current version
|
400 |
st.session_state.cleaned_data = st.session_state.data_versions[-1].copy() # Set data
|
401 |
st.success("Last action undone!")
|
|
|
402 |
|
403 |
# --------------------------
|
404 |
# Missing Value Handling
|
|
|
439 |
new_df[cols] = new_df[cols].bfill()
|
440 |
|
441 |
update_cleaned_data(new_df)
|
442 |
+
|
|
|
443 |
except Exception as e:
|
444 |
st.error(f"Error: {str(e)}")
|
445 |
else:
|
|
|
480 |
new_df[col_to_convert] = pd.to_datetime(new_df[col_to_convert], format=date_format, errors='coerce')
|
481 |
|
482 |
update_cleaned_data(new_df)
|
|
|
483 |
except Exception as e:
|
484 |
st.error(f"Error: {str(e)}")
|
485 |
|
|
|
495 |
new_df = df.copy()
|
496 |
new_df = new_df.drop(columns=columns_to_drop)
|
497 |
update_cleaned_data(new_df)
|
|
|
498 |
|
499 |
# --------------------------
|
500 |
# Label Encoding
|
|
|
511 |
new_df[col] = le.fit_transform(new_df[col].astype(str))
|
512 |
label_encoders[col] = le
|
513 |
update_cleaned_data(new_df)
|
|
|
514 |
|
515 |
# --------------------------
|
516 |
# StandardScaler
|
|
|
525 |
scaler = StandardScaler()
|
526 |
new_df[scale_cols] = scaler.fit_transform(new_df[scale_cols])
|
527 |
update_cleaned_data(new_df)
|
|
|
528 |
except Exception as e:
|
529 |
st.error(f"Error: {str(e)}")
|
530 |
|
|
|
558 |
text_cols = new_df.select_dtypes(include='object').columns
|
559 |
new_df[text_cols] = new_df[text_cols].apply(lambda x: x.str.strip())
|
560 |
update_cleaned_data(new_df)
|
|
|
561 |
|
562 |
# --------------------------
|
563 |
# Cleaned Data Preview
|
|
|
565 |
if st.session_state.get("cleaned_data") is not None:
|
566 |
enhance_section_title("Cleaned Data Preview", "✨")
|
567 |
with st.expander("✨ Cleaned Data Preview", expanded=True):
|
568 |
+
st.dataframe(
|
569 |
+
st.session_state.cleaned_data.head(),
|
570 |
+
use_container_width=True,
|
571 |
+
height=400 # <-- Add height parameter here
|
572 |
+
)
|
573 |
|
574 |
# --------------------------
|
575 |
# EDA
|