Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -38,29 +38,21 @@ def format_table_data(data_string):
|
|
38 |
# Split each row into columns based on the separator '|' and strip extra spaces
|
39 |
columns = row.split("|")
|
40 |
formatted_row = [cell.strip() for cell in columns]
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
42 |
formatted_data.append(formatted_row)
|
43 |
|
44 |
-
#
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
# Transpose the data to work with columns
|
49 |
-
transposed_data = list(map(list, zip(*formatted_data)))
|
50 |
-
|
51 |
-
# Filter out outlier columns
|
52 |
-
filtered_columns = [col for col in transposed_data if min_elements <= len(col) <= max_elements]
|
53 |
-
|
54 |
-
# Transpose the data back to the original format
|
55 |
-
filtered_data = list(map(list, zip(*filtered_columns)))
|
56 |
-
|
57 |
-
# Handle uneven rows by ensuring each row has the same number of columns
|
58 |
-
max_columns = max(len(row) for row in filtered_data)
|
59 |
-
for row in filtered_data:
|
60 |
while len(row) < max_columns:
|
61 |
row.append("") # Add empty strings to fill the row
|
62 |
|
63 |
-
return
|
64 |
|
65 |
#==========================================================================================================
|
66 |
|
|
|
38 |
# Split each row into columns based on the separator '|' and strip extra spaces
|
39 |
columns = row.split("|")
|
40 |
formatted_row = [cell.strip() for cell in columns]
|
41 |
+
|
42 |
+
# Handle uneven rows by ensuring each row has the same number of columns
|
43 |
+
max_columns = max(len(columns) for columns in formatted_data) if formatted_data else len(columns)
|
44 |
+
while len(formatted_row) < max_columns:
|
45 |
+
formatted_row.append("") # Add empty strings to fill the row
|
46 |
+
|
47 |
formatted_data.append(formatted_row)
|
48 |
|
49 |
+
# Handle case where new rows have more columns than previous rows
|
50 |
+
max_columns = max(len(row) for row in formatted_data)
|
51 |
+
for row in formatted_data:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
while len(row) < max_columns:
|
53 |
row.append("") # Add empty strings to fill the row
|
54 |
|
55 |
+
return formatted_data
|
56 |
|
57 |
#==========================================================================================================
|
58 |
|