Skip to content

pandas: tabulate shows column different based on column count #390

@skwde

Description

@skwde

tabulate formats dataframe column different based on dataframe column count.
here is a MWE:

import pandas as pd
from tabulate import tabulate

t = pd.DataFrame(data=range(5), index=range(5))
t[0] = pd.to_timedelta(t[0], unit="h")


print(
    tabulate(
        t,
        headers="keys",
        showindex="always",
    )
)

t[1] = 0

print(
    tabulate(
        t,
        headers="keys",
        showindex="always",
    )
)

with output

           0
--  --------
 0  0
 1  3.6e+12
 2  7.2e+12
 3  1.08e+13
 4  1.44e+13
    0                  1
--  ---------------  ---
 0  0 days 00:00:00    0
 1  0 days 01:00:00    0
 2  0 days 02:00:00    0
 3  0 days 03:00:00    0
 4  0 days 04:00:00    0

Versions:

  • python: 3.14.2
  • pandas: 2.3.3
  • tabulate: 0.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions