BUG: to_string with index=False incorrectly shifts truncation (ellipsis) column · Issue #40904 · pandas-dev/pandas (original) (raw)


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd df = pd.DataFrame([[0]*100] * 10) print(df.to_string(index=False, max_cols=20))

Output

 0   1   2   3   4   5   6   7   8   9   90  ...  91  92  93  94  95  96  97  98  99
  0   0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0

Problem description

to_string is placing the truncation column (i.e. the column with the ellipses) one position too far to the right. This should not happen.

Expected Output

 0   1   2   3   4   5   6   7   8   9   ...  90  91  92  93  94  95  96  97  98  99
  0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0   0   0  ...   0   0   0   0   0   0   0   0   0   0

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f2c8480
python : 3.9.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 1.2.3
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 54.1.2
Cython : None
pytest : 6.2.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.22.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None