Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
909 B
1
Indexable
Never
import json

# Assuming 'x' is the list containing your extracted tables

# Initialize a dictionary to store the organized data
organized_data = {}

# Iterate through the tables
for i, table in enumerate(x):
    table_name = f"Table_{i + 1}"  # You can assign meaningful names to your tables here
    
    # Extract the headers (first row) and data (remaining rows) separately
    headers = table[0].split()
    data = [row.split() for row in table[1:]]
    
    # Create a list of dictionaries where each dictionary represents a row
    table_data = [dict(zip(headers, row)) for row in data]
    
    # Store the organized table data in the dictionary
    organized_data[table_name] = table_data

# Serialize the organized data to JSON
json_data = json.dumps(organized_data)

# Now, 'json_data' contains your organized data in JSON format
# You can send it to your React frontend for rendering in a grid.