| #!/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") | |