INNER CODE UNIT · Python

format_as_table

evangelosmeklis/peepdb · peepdb/core.py:101

def format_as_table(data: Dict[str, Any]) -> str:
    formatted_result = []
    for table_name, table_data in data.items():
        formatted_result.append(f"Table: {table_name}")
        if table_data['data']:
            headers = table_data['data'][0].keys()
            table_rows = [list(row.values()) for row in table_data['data']]
            formatted_result.append(tabulate(table_rows, headers=headers, tablefmt='grid'))
        else:
            formatted_result.append("No data")
        formatted_result.append(
            f"Page {table_data['page']} of {table_data['total_pages']} (Total rows: {table_data['total_rows']})"
        )
        formatted_result.append("")
    return "\n".join(formatted_result).strip()


def format_value(value, scientific: bool, output_format: str):

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…