AMKhakbaz commited on
Commit
dc243ed
·
verified ·
1 Parent(s): e0c86d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -410,23 +410,27 @@ def analyze_z_test(file):
410
 
411
  return result_dataframes
412
 
413
- def join_dataframes(mlist ,dataframes):
414
  max_rows = max(df.shape[0] for df in dataframes)
415
  result = pd.DataFrame()
416
- i = 1
417
- for df in dataframes:
 
418
  rows_to_add = max_rows - df.shape[0]
419
  if rows_to_add > 0:
420
- # Create a DataFrame with empty rows
421
  empty_rows = pd.DataFrame(index=range(rows_to_add), columns=df.columns)
422
- #Fill empty rows with np.nan
423
  empty_rows = empty_rows.fillna(np.nan)
424
-
425
  df = pd.concat([df, empty_rows], ignore_index=True)
426
- if not result.empty:
427
- result = pd.concat([result, pd.DataFrame(columns=[mlist[i]])], axis=1)
428
- i += 1
429
 
 
 
 
 
 
 
 
 
 
430
  result = pd.concat([result, df.reset_index(drop=True)], axis=1)
431
 
432
  return result
 
410
 
411
  return result_dataframes
412
 
413
+ def join_dataframes(mlist, dataframes):
414
  max_rows = max(df.shape[0] for df in dataframes)
415
  result = pd.DataFrame()
416
+ col_counts = {} # Dictionary to track column name occurrences
417
+
418
+ for i, df in enumerate(dataframes):
419
  rows_to_add = max_rows - df.shape[0]
420
  if rows_to_add > 0:
 
421
  empty_rows = pd.DataFrame(index=range(rows_to_add), columns=df.columns)
 
422
  empty_rows = empty_rows.fillna(np.nan)
 
423
  df = pd.concat([df, empty_rows], ignore_index=True)
 
 
 
424
 
425
+ for col in df.columns:
426
+ original_col = col
427
+ count = 1
428
+ while col in result.columns:
429
+ col = f"{original_col}_{count}"
430
+ count += 1
431
+ col_counts[original_col] = col_counts.get(original_col, 0) + 1
432
+ df = df.rename(columns={original_col: col})
433
+
434
  result = pd.concat([result, df.reset_index(drop=True)], axis=1)
435
 
436
  return result