CosmickVisions commited on
Commit
417011c
·
verified ·
1 Parent(s): 9923660

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -32
app.py CHANGED
@@ -1088,43 +1088,44 @@ elif app_mode == "EDA":
1088
  st.subheader("Data Transformation")
1089
  transform_col = st.selectbox("Column to transform", df.select_dtypes(include=[np.number]).columns)
1090
  transform_type = st.selectbox("Transformation", ["Log", "Square Root", "Z-score", "Standardization", "Normalization", "Box-Cox", "Inverse"])
1091
-
1092
  fig, ax = plt.subplots(1, 2, figsize=(12, 5))
1093
-
1094
  if transform_col:
1095
  sns.histplot(df[transform_col], bins=30, kde=True, ax=ax[0])
1096
  ax[0].set_title('Before Transformation')
1097
-
1098
- if transform_type == "Log":
1099
- df[transform_col] = np.log1p(df[transform_col])
1100
- elif transform_type == "Square Root":
1101
- df[transform_col] = np.sqrt(df[transform_col])
1102
- elif transform_type == "Z-score":
1103
- df[transform_col] = (df[transform_col] - df[transform_col].mean())/df[transform_col].std()
1104
- elif transform_type == "Standardization":
1105
- df[transform_col] = (df[transform_col] - df[transform_col].mean()) / df[transform_col].std()
1106
- elif transform_type == "Normalization":
1107
- df[transform_col] = (df[transform_col] - df[transform_col].min()) / (df[transform_col].max() - df[transform_col].min())
1108
- elif transform_type == "Box-Cox":
1109
- df[transform_col], _ = boxcox(df[transform_col] + 1) # Adding 1 to avoid log(0) error
1110
- elif transform_type == "Inverse":
1111
- df[transform_col] = 1 / df[transform_col]
1112
-
1113
- sns.histplot(df[transform_col], bins=30, kde=True, ax=ax[1])
1114
- ax[1].set_title('After Transformation')
1115
-
1116
- st.pyplot(fig)
 
 
 
 
 
 
 
 
 
1117
  else:
1118
- st.warning("Please select a column for transformation.")
1119
-
1120
- # Error handling for invalid transformations
1121
- try:
1122
- if transform_type == "Log" and (df[transform_col] <= 0).any():
1123
- st.error("Log transformation is not applicable to non-positive values.")
1124
- elif transform_type == "Box-Cox" and (df[transform_col] <= 0).any():
1125
- st.error("Box-Cox transformation requires all values to be positive.")
1126
- except Exception as e:
1127
- st.error(f"Transformation failed: {str(e)}")
1128
 
1129
  enhance_section_title("Export Options", "💾")
1130
  st.subheader("💾 Export Options")
 
1088
  st.subheader("Data Transformation")
1089
  transform_col = st.selectbox("Column to transform", df.select_dtypes(include=[np.number]).columns)
1090
  transform_type = st.selectbox("Transformation", ["Log", "Square Root", "Z-score", "Standardization", "Normalization", "Box-Cox", "Inverse"])
1091
+
1092
  fig, ax = plt.subplots(1, 2, figsize=(12, 5))
1093
+
1094
  if transform_col:
1095
  sns.histplot(df[transform_col], bins=30, kde=True, ax=ax[0])
1096
  ax[0].set_title('Before Transformation')
1097
+
1098
+ if transform_type == "Log":
1099
+ df[transform_col] = np.log1p(df[transform_col])
1100
+ elif transform_type == "Square Root":
1101
+ df[transform_col] = np.sqrt(df[transform_col])
1102
+ elif transform_type == "Z-score":
1103
+ df[transform_col] = (df[transform_col] - df[transform_col].mean())/df[transform_col].std()
1104
+ elif transform_type == "Standardization":
1105
+ df[transform_col] = (df[transform_col] - df[transform_col].mean()) / df[transform_col].std()
1106
+ elif transform_type == "Normalization":
1107
+ df[transform_col] = (df[transform_col] - df[transform_col].min()) / (df[transform_col].max() - df[transform_col].min())
1108
+ elif transform_type == "Box-Cox":
1109
+ df[transform_col], _ = boxcox(df[transform_col] + 1) # Adding 1 to avoid log(0) error
1110
+ elif transform_type == "Inverse":
1111
+ df[transform_col] = 1 / df[transform_col]
1112
+
1113
+ sns.histplot(df[transform_col], bins=30, kde=True, ax=ax[1])
1114
+ ax[1].set_title('After Transformation')
1115
+
1116
+ st.pyplot(fig)
1117
+
1118
+ # Error handling for invalid transformations
1119
+ try:
1120
+ if transform_type == "Log" and (df[transform_col] <= 0).any():
1121
+ st.error("Log transformation is not applicable to non-positive values.")
1122
+ elif transform_type == "Box-Cox" and (df[transform_col] <= 0).any():
1123
+ st.error("Box-Cox transformation requires all values to be positive.")
1124
+ except Exception as e:
1125
+ st.error(f"Transformation failed: {str(e)}")
1126
  else:
1127
+ st.warning("Please select a column for transformation.")
1128
+
 
 
 
 
 
 
 
 
1129
 
1130
  enhance_section_title("Export Options", "💾")
1131
  st.subheader("💾 Export Options")