File size: 597 Bytes
c5c6773
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env python3
"""Table Formatting Plugin"""
import pandas as pd
from tabulate import tabulate

class TableFormatter:
    """Format DataFrames as tables."""
    def format_to_markdown(self, df: pd.DataFrame, headers: str = "keys") -> str:
        if df.empty:
            return "No data to display."
        return tabulate(df, headers=headers, tablefmt="github", showindex=False)
    
    def format_to_html(self, df: pd.DataFrame) -> str:
        if df.empty:
            return "No data to display."
        return df.to_html(index=False, classes="table-auto w-full text-left border")