bug in to_html() with formatters= and max_cols · Issue #25955 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
import pandas as pd import pandas.util.testing as tm df = tm.makeDataFrame()[:5] fmt = lambda x: str(x)+'_mod' formatters=[fmt,fmt,None,None] print(df.to_html(formatters=formatters)) print(df.to_html(formatters=formatters, max_cols=3))
A | B | C | D | |
---|---|---|---|---|
auVRHDVXKo | 0.8480611318869997_mod | 2.4785562034246165_mod | -1.258639 | 1.134326 |
4IL8N5I4tk | -0.4349431395826644_mod | 1.491615558543841_mod | -1.392170 | -1.119832 |
PACjyGDGOG | -0.8963777799744853_mod | 0.5011278874888623_mod | -0.475899 | 1.041362 |
dGFzef3Sbf | 0.2615536705949168_mod | 1.4994356591304039_mod | 0.713050 | -0.613034 |
U2mGzTnuUi | -0.8803411110313392_mod | -0.5522186462569404_mod | 0.309005 | -1.715071 |
A | ... | D | |
---|---|---|---|
auVRHDVXKo | 0.8480611318869997_mod | ... | 1.134326092661258_mod |
4IL8N5I4tk | -0.4349431395826644_mod | ... | -1.1198318989339953_mod |
PACjyGDGOG | -0.8963777799744853_mod | ... | 1.0413616487242832_mod |
dGFzef3Sbf | 0.2615536705949168_mod | ... | -0.6130344240242487_mod |
U2mGzTnuUi | -0.8803411110313392_mod | ... | -1.7150707649504604_mod |
Problem description
When a list of formatters is given, the integer position of the truncated dataframe is used to lookup the formatter.
the same problem also occurs for to_string()
Expected Output
A | ... | D | |
---|---|---|---|
auVRHDVXKo | 0.8480611318869997_mod | ... | 1.134326 |
4IL8N5I4tk | -0.4349431395826644_mod | ... | -1.119832 |
PACjyGDGOG | -0.8963777799744853_mod | ... | 1.041362 |
dGFzef3Sbf | 0.2615536705949168_mod | ... | -0.613034 |
U2mGzTnuUi | -0.8803411110313392_mod | ... | -1.715071 |
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.7.2.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.25.0.dev0+348.gb727c6b32
pytest: 4.3.0
pip: 19.0.3
setuptools: 40.6.3
Cython: 0.29.5
numpy: 1.16.2
scipy: 1.2.1
pyarrow: 0.11.1
xarray: 0.11.3
IPython: 7.3.0
sphinx: 1.8.4
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.9
feather: None
matplotlib: 3.0.2
openpyxl: 2.6.0
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.5
lxml.etree: 4.3.1
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.2.18
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: 0.2.0
fastparquet: 0.2.1
pandas_gbq: None
pandas_datareader: None
gcsfs: None