AMKhakbaz commited on
Commit
59fd7c2
·
verified ·
1 Parent(s): dcc8553

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -17
app.py CHANGED
@@ -173,21 +173,22 @@ def z_testes(n1, n2, p1, p2):
173
  return np.nan
174
 
175
  def z_test_data(df):
176
-
177
- rows, cols = df.shape
178
- styles = pd.DataFrame('background-color: lightgray;', index=df.index, columns=df.columns)
179
-
180
- for i in range(rows-2):
181
- for j in range(cols-2):
182
- n1 = df.iloc[-1, -1] # x_IJ
183
- n2 = df.iloc[-1, j] # x_Ij
184
- p1 = df.iloc[i, -1] # x_1J
185
- p2 = df.iloc[i, j] # x_ij
 
186
  p_value = z_testes(n1, n2, p1, p2)
187
- if p_value <= 0.05:
188
- styles.iloc[i, j] = 'background-color: lightgreen;'
189
-
190
- return df.style.apply(lambda x: styles, axis=None)
191
 
192
  def Z_test_dataframes(sheets_data):
193
  """Processes each sheet's DataFrame and computes new DataFrames with Z-test results."""
@@ -339,7 +340,8 @@ if main_option == "Tabulation":
339
  percentile_df, frequency_df = two_variable_ss(df[[var1, var2]], var1, var2)
340
  st.subheader("Percentage Table")
341
  #st.dataframe(z_test_data(percentile_df), unsafe_allow_html=True)
342
- st.dataframe(z_test_data(percentile_df), use_container_width=True)
 
343
 
344
  st.subheader("Frequency Table")
345
  st.dataframe(frequency_df)
@@ -353,7 +355,8 @@ if main_option == "Tabulation":
353
  percentile_df, frequency_df = two_variable_sm(df[[var1] + matching_cols], var1, matching_cols)
354
  st.subheader("Percentage Table")
355
  #st.dataframe(z_test_data(percentile_df), unsafe_allow_html=True)
356
- st.dataframe(z_test_data(percentile_df), use_container_width=True)
 
357
 
358
  st.subheader("Frequency Table")
359
  st.dataframe(frequency_df)
@@ -371,7 +374,8 @@ if main_option == "Tabulation":
371
  percentile_df, frequency_df = two_variable_mm(df[matching_cols1 + matching_cols2], matching_cols1, matching_cols2)
372
  st.subheader("Percentage Table")
373
  #st.dataframe(z_test_data(percentile_df), unsafe_allow_html=True)
374
- st.dataframe(z_test_data(percentile_df), use_container_width=True)
 
375
 
376
  st.subheader("Frequency Table")
377
  st.dataframe(frequency_df)
 
173
  return np.nan
174
 
175
  def z_test_data(df):
176
+ styles = pd.DataFrame('', index=df.index, columns=df.columns)
177
+
178
+ num_rows, num_cols = df.shape
179
+ sample_size = df.iloc[-1, -1] # Total sample size
180
+
181
+ for i in range(num_rows -1):
182
+ for j in range(1, num_cols -1):
183
+ n1 = df.iloc[-1, -1]
184
+ n2 = df.iloc[-1, j]
185
+ p1 = df.iloc[i, -1]
186
+ p2 = df.iloc[i, j]
187
  p_value = z_testes(n1, n2, p1, p2)
188
+ if pd.notnull(p_value) and p_value <= 0.05:
189
+ styles.iloc[i, j] = 'background-color: lightgreen'
190
+
191
+ return df.style.apply(lambda _: styles, axis=None)
192
 
193
  def Z_test_dataframes(sheets_data):
194
  """Processes each sheet's DataFrame and computes new DataFrames with Z-test results."""
 
340
  percentile_df, frequency_df = two_variable_ss(df[[var1, var2]], var1, var2)
341
  st.subheader("Percentage Table")
342
  #st.dataframe(z_test_data(percentile_df), unsafe_allow_html=True)
343
+ #st.dataframe(z_test_data(percentile_df), use_container_width=True)
344
+ st.write(z_test_data(percentile_df))
345
 
346
  st.subheader("Frequency Table")
347
  st.dataframe(frequency_df)
 
355
  percentile_df, frequency_df = two_variable_sm(df[[var1] + matching_cols], var1, matching_cols)
356
  st.subheader("Percentage Table")
357
  #st.dataframe(z_test_data(percentile_df), unsafe_allow_html=True)
358
+ #st.dataframe(z_test_data(percentile_df), use_container_width=True)
359
+ st.write(z_test_data(percentile_df))
360
 
361
  st.subheader("Frequency Table")
362
  st.dataframe(frequency_df)
 
374
  percentile_df, frequency_df = two_variable_mm(df[matching_cols1 + matching_cols2], matching_cols1, matching_cols2)
375
  st.subheader("Percentage Table")
376
  #st.dataframe(z_test_data(percentile_df), unsafe_allow_html=True)
377
+ #st.dataframe(z_test_data(percentile_df), use_container_width=True)
378
+ st.write(z_test_data(percentile_df))
379
 
380
  st.subheader("Frequency Table")
381
  st.dataframe(frequency_df)