-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DataFrame output too wide / not truncated properly #32461
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
Comments
I'm having this problem too (can confirm it's still happening on main branch). The width of the DataFrame's repr exceeds terminal width by up to 4 characters. I think this function is not accounting for the added width of the pandas/pandas/io/formats/string.py Lines 159 to 192 in 2e218d1
|
Minimal example that reproduces this problem with Pandas 2.1.4: >>> import os, pandas
>>> os.get_terminal_size()
os.terminal_size(columns=93, lines=47)
>>> df=pandas.DataFrame({"Date": "2023-08-31 00:00:00-04:00", "Open": 187.839996, "High": 189
.119995, "Low": 187.479996, "Close": 187.869995, "Volume": 60735600, "Dividends": 0.0, "Stock
Splits": 0.0}, index=[10769])
>>> df
Date Open High ... Volume Dividends Stock Spl
its
10769 2023-08-31 00:00:00-04:00 187.839996 189.119995 ... 60735600 0.0
0.0
[1 rows x 8 columns] |
Problem description
It seems to me, that DataFrames are not always correctly trunctaed to fit the terminal width (using pandas 1.0.1).
My pandas config is set such, that it auto detects terminal width and the representation of the DataFrame should fit in.
Relevant pandas config settings
Code Sample
Please resize terminal to have width 127 to reproduce
Check with shutil.get_terminal_size()
The lines of the string representation of the DataFrame are too long, therefore each line spans across two lines (depending on the terminal width; with the given settings it needs 129 characters instead of the available 127). To me this looks like a bug in the DataFrameFormatter. As I understand probably in the write_result method line 839ff
Could that be?
By the way, I also don't quite understand the display.expand_frame_repr setting. It is now set to True. When I set it to False the DataFrame does not get truncated but the full represenation is printed across multiple lines. Shouldn't that be excactly the other way round?
The following issue seems to be related, but I did not find the exact same problem. Hope I didn't miss anything: #16911
Expected Output
A DataFrame representation truncated such, that each line fits the terminal width.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.2.0.post20200209
Cython : 0.29.15
pytest : None
hypothesis : None
sphinx : 2.4.3
blosc : None
feather : 0.4.0
xlsxwriter : 1.2.8
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.4 (dt dec pq3 ext lo64)
jinja2 : 2.11.1
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : 1.3.2
fastparquet : 0.3.3
gcsfs : None
lxml.etree : None
matplotlib : 3.2.0
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : 0.15.1
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.13
tables : 3.6.1
tabulate : None
xarray : 0.15.0
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.2.8
numba : 0.48.0
The text was updated successfully, but these errors were encountered: