Skip to content

BUG:Dataframe.to_string, when set index=False, there is a white space in the head of every line #35561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 3 tasks
ZephyrShannon opened this issue Aug 5, 2020 · 2 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@ZephyrShannon
Copy link

ZephyrShannon commented Aug 5, 2020

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


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
d = {'col1': ["1", "2", "3"], 'col2': [4, 5, 6]}
df = pd.DataFrame(d)
print(df.to_string(index=False, formatters={'col1':'{:10}'.format}))

Problem description

there is a white space in the head of every line:
col1 col2
1 4
2 5
3 6

Expected Output

no white space in the head
col1 col2
1 4
2 5
3 6

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.3.final.0 python-bits: 64 OS: Darwin OS-release: 19.5.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: None LOCALE: zh_CN.UTF-8 pandas: 0.24.2 pytest: None pip: 19.0.3 setuptools: 41.0.0 Cython: None numpy: 1.16.4 scipy: 1.3.0 pyarrow: None xarray: None IPython: 7.5.0 sphinx: None patsy: None dateutil: 2.8.0 pytz: 2019.1 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: 3.1.0 openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml.etree: 4.5.1 bs4: None html5lib: None sqlalchemy: None pymysql: None psycopg2: None jinja2: 2.10.1 s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: 0.8.1 gcsfs: None
@ZephyrShannon ZephyrShannon added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 5, 2020
@linchiwei123
Copy link

try this. documentation

print(df.to_string(index=False, formatters={'col1':'{:10}'.format}, justify="left"))

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Sep 4, 2020

Duplicate of #24980 I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

3 participants