CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-tabulate

tessl install tessl/pypi-tabulate@0.9.0

Pretty-print tabular data in Python with extensive formatting options and output format support.

Agent Success

Agent success rate when using this tile

69%

Improvement

Agent success rate improvement when using this tile compared to baseline

0.9x

Baseline

Agent success rate without this tile

77%

task.mdevals/scenario-9/

Sales Report Formatter

Create a Python program that formats sales data into well-aligned tables with specific column alignment.

Requirements

Your program should accept sales data (as a list of lists) and column headers, then return a formatted table string with the following alignment:

  1. The first column (Product ID) should be right-aligned
  2. The second column (Product Name) should be left-aligned
  3. The third column (Category) should be center-aligned
  4. The remaining numeric columns should be aligned by decimal point

Test Cases

Test case 1: Per-column alignment

When formatting this data:

data = [
    [101, "Widget A", "Electronics", 45, 2250.50],
    [2, "Gadget Premium", "Home", 123, 15372.25],
    [3456, "Tool X", "Garden", 8, 159.99]
]
headers = ["Product ID", "Product Name", "Category", "Units Sold", "Revenue"]

The formatted table should have Product ID right-aligned, Product Name left-aligned, Category center-aligned, and numeric columns (Units Sold, Revenue) aligned by decimal point.

@test

Test case 2: Global alignment with specific override

When formatting this data:

data = [
    [500, "Premium Item", "Luxury", 5, 9999.99],
    [25, "Budget Item", "Economy", 250, 125.00]
]
headers = ["ID", "Item", "Type", "Qty", "Price"]

The table should have all columns right-aligned by default, except the "Item" column which should be left-aligned.

@test

Test case 3: String and numeric column defaults

When formatting this financial data:

data = [
    ["Q1 2024", 125000.5, 98234.125, 26766.375],
    ["Q2 2024", 142500.0, 105670.0, 36830.0],
    ["Q3 2024", 98750.25, 82109.5, 16640.75]
]
headers = ["Quarter", "Revenue", "Costs", "Profit"]

String columns should be left-aligned while numeric columns should be aligned by decimal point.

@test

Implementation

@generates

API

def format_sales_report(data, headers):
    """
    Format sales data into an aligned table.

    Args:
        data: List of lists containing sales records
        headers: List of column header strings

    Returns:
        str: Formatted table with custom column alignments
    """

Dependencies { .dependencies }

tabulate { .dependency }

Provides table formatting and alignment capabilities.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/tabulate@0.9.x
tile.json