Update app.py
Browse files
app.py
CHANGED
@@ -21,6 +21,31 @@ def extract_table_from_markdown(markdown_text, table_start):
|
|
21 |
table_content.append(line)
|
22 |
return '\n'.join(table_content)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def markdown_table_to_df(table_content):
|
25 |
"""Convert markdown table to pandas DataFrame."""
|
26 |
# Split the table content into lines
|
@@ -33,8 +58,10 @@ def markdown_table_to_df(table_content):
|
|
33 |
data = []
|
34 |
for line in lines[2:]: # Skip the header separator line
|
35 |
row = [cell.strip() for cell in line.split('|') if cell.strip()]
|
36 |
-
if row
|
37 |
-
|
|
|
|
|
38 |
|
39 |
# Create DataFrame
|
40 |
df = pd.DataFrame(data, columns=headers)
|
|
|
21 |
table_content.append(line)
|
22 |
return '\n'.join(table_content)
|
23 |
|
24 |
+
# def markdown_table_to_df(table_content):
|
25 |
+
# """Convert markdown table to pandas DataFrame."""
|
26 |
+
# # Split the table content into lines
|
27 |
+
# lines = table_content.split('\n')
|
28 |
+
|
29 |
+
# # Extract headers
|
30 |
+
# headers = [h.strip() for h in lines[0].split('|') if h.strip()]
|
31 |
+
|
32 |
+
# # Extract data
|
33 |
+
# data = []
|
34 |
+
# for line in lines[2:]: # Skip the header separator line
|
35 |
+
# row = [cell.strip() for cell in line.split('|') if cell.strip()]
|
36 |
+
# if row and len(row) == len(headers): # Ensure row has the correct number of columns
|
37 |
+
# data.append(row)
|
38 |
+
|
39 |
+
# # Create DataFrame
|
40 |
+
# df = pd.DataFrame(data, columns=headers)
|
41 |
+
|
42 |
+
# # Convert numeric columns to float
|
43 |
+
# for col in df.columns:
|
44 |
+
# if col not in ["Model Name", "Publisher", "Open?", "Basemodel", "Matryoshka"]:
|
45 |
+
# df[col] = pd.to_numeric(df[col], errors='coerce')
|
46 |
+
|
47 |
+
# return df
|
48 |
+
|
49 |
def markdown_table_to_df(table_content):
|
50 |
"""Convert markdown table to pandas DataFrame."""
|
51 |
# Split the table content into lines
|
|
|
58 |
data = []
|
59 |
for line in lines[2:]: # Skip the header separator line
|
60 |
row = [cell.strip() for cell in line.split('|') if cell.strip()]
|
61 |
+
if row: # Include any non-empty row
|
62 |
+
# Pad the row with empty strings if it's shorter than the headers
|
63 |
+
padded_row = row + [''] * (len(headers) - len(row))
|
64 |
+
data.append(padded_row[:len(headers)]) # Trim if longer than headers
|
65 |
|
66 |
# Create DataFrame
|
67 |
df = pd.DataFrame(data, columns=headers)
|