Skip to content

BUG: output of df.to_string depends on whether columns is a CategoricalIndex or not #35439

Closed
@topper-123

Description

@topper-123

The output of df.to_string is different if the columns is a CategoricalIndex rather than a normal Index:

>>> data = [[4, 2], [3, 2], [4, 3]]
>>> cols = ["aaaaaaaaa", "b"]
>>>  pd.DataFrame(data, columns=cols)
   aaaaaaaaa  b
0          4  2
1          3  2
2          4  3
>>> pd.DataFrame(data, columns=pd.CategoricalIndex(cols))
   aaaaaaaaa  b
0          4          2
1          3          2
2          4          3

We can see that the width of the "b" column depends on the width of the "a" column, if the columns are a CategoricalIndex.

These two examples should return the same repr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexRelated to the Index class or subclassesOutput-Formatting__repr__ of pandas objects, to_stringRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions