Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,9 +30,26 @@ def format_table_data(data_string):
|
|
| 30 |
# Split the string into rows based on newlines
|
| 31 |
rows = data_string.strip().split("\n")
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
return formatted_data
|
| 38 |
|
|
|
|
| 30 |
# Split the string into rows based on newlines
|
| 31 |
rows = data_string.strip().split("\n")
|
| 32 |
|
| 33 |
+
# Initialize a list to store the formatted data
|
| 34 |
+
formatted_data = []
|
| 35 |
+
|
| 36 |
+
for row in rows:
|
| 37 |
+
# Split each row into columns based on the separator '|' and strip extra spaces
|
| 38 |
+
columns = row.split("|")
|
| 39 |
+
formatted_row = [cell.strip() for cell in columns]
|
| 40 |
+
|
| 41 |
+
# Handle uneven rows by ensuring each row has the same number of columns
|
| 42 |
+
max_columns = max(len(columns) for columns in formatted_data) if formatted_data else len(columns)
|
| 43 |
+
while len(formatted_row) < max_columns:
|
| 44 |
+
formatted_row.append("") # Add empty strings to fill the row
|
| 45 |
+
|
| 46 |
+
formatted_data.append(formatted_row)
|
| 47 |
+
|
| 48 |
+
# Handle case where new rows have more columns than previous rows
|
| 49 |
+
max_columns = max(len(row) for row in formatted_data)
|
| 50 |
+
for row in formatted_data:
|
| 51 |
+
while len(row) < max_columns:
|
| 52 |
+
row.append("") # Add empty strings to fill the row
|
| 53 |
|
| 54 |
return formatted_data
|
| 55 |
|