BUG: `style.hide(axis='index')` doesn't show text within angle brackets

This issue has been created since 2022-11-22.

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import io
df = pd.read_csv(io.StringIO("""
x,y
<asdf>,1
qwer,2
<asdf>qwer,3
qwer<asdf>,4
qw<asdf>er,5
"""))
df.style.hide(axis='index')

Issue Description

The text between the angle brackets (inclusive) are not displayed. The output looks like this:

x    | y
---- | --
     | 1
qwer | 2
qwer | 3
qwer | 4
qwer | 5

Expected Behavior

Something like:

x y
<asdf> 1
qwer 2
<asdf>qwer 3
qwer<asdf> 4
qw<asdf>er 5

df.style.to_string() and df.style.to_html() work as expected.

Installed Versions

INSTALLED VERSIONS
------------------
commit           : 91111fd99898d9dcaa6bf6bedb662db4108da6e6
python           : 3.9.13.final.0
python-bits      : 64
OS               : Darwin
OS-release       : 21.6.0
Version          : Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : en_US.UTF-8
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.5.1
numpy            : 1.23.2
pytz             : 2022.2.1
dateutil         : 2.8.2
setuptools       : 65.3.0
pip              : 22.2.2
Cython           : None
pytest           : 7.1.3
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : 4.9.1
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 3.1.2
IPython          : 8.5.0
pandas_datareader: None
bs4              : 4.11.1
bottleneck       : None
brotli           : 
fastparquet      : None
fsspec           : 2022.8.2
gcsfs            : None
matplotlib       : 3.5.3
numba            : None
numexpr          : None
odfpy            : None
openpyxl         : 3.0.10
pandas_gbq       : None
pyarrow          : 9.0.0
pyreadstat       : None
pyxlsb           : None
s3fs             : 0.4.2
scipy            : 1.9.1
snappy           : None
sqlalchemy       : 1.4.41
tables           : None
tabulate         : 0.8.10
xarray           : 2022.6.0
xlrd             : 2.0.1
xlwt             : None
zstandard        : None
tzdata           : None
attack68 wrote this answer on 2022-11-22

What are you using to produce output? Jupyter notebook?

It will interpret angle brackets as HTML and therefore the output from STyler is correct but your browser is parsing it away.
An option is to try escaping. df.style.hide(axis='index').format(escape="html")

attack68 wrote this answer on 2022-11-22
saiwing-yeung wrote this answer on 2022-11-22

Thank you!

Wondering what the next step should be? If pandas is capable of detecting whether it's running inside a browser, would it be possible to default to .format(escape="html") if so?

attack68 wrote this answer on 2022-11-22

No, there are no next steps. The argument is offered and documented so that users can use it depending upon the environment they operate it. Pandas will not (and cannot) attempt to guess the users intent and adjust itself based on that info. Pandas will also not (and cannot) maintain an exhaustive list of possible environments and combinatorial argument defaults.

Thanks for the query.

Edit: you can use the global pandas options for Styler which allows you to set escape globally if you so wish

saiwing-yeung wrote this answer on 2022-11-22

That's fair, thanks for the tips and looking into this.

More Details About Repo
Owner Name pandas-dev
Repo Name pandas
Full Name pandas-dev/pandas
Language Python
Created Date 2010-08-24
Updated Date 2022-12-07
Star Count 36164
Watcher Count 1118
Fork Count 15472
Issue Count 3683

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Failed to establish a new connection: [Errno 113] No route to host')) 1 2022-11-25 2022-11-28
Ошибка изменения имени в диалогах 0 2022-09-06 2022-09-17
Add links doesn't work unless the file already exists 1 2021-09-29 2022-08-27
Solución Reto #34 JavaScript 0 2022-08-24 2022-12-03
error : Remote HTTP 404: Not Found 0 2022-04-13 2022-11-03
Compile `Mode`s still uses "optimize" instead of "rewrite" 2 2022-09-05 2022-10-22
[meta] v0.3 release checklist 0 2021-10-07 2022-12-03
crypto.com API does not send any sell orders 2 2021-05-10 2022-07-01
Need ERC721 library using PHP 4 2021-11-19 2022-10-28
No distinction by colour 6 2021-03-28 2022-11-25
Add --meryldb parameter 2 2021-06-28 2022-12-06
force an error when --profile is used instead of -profile 1 2021-06-16 2022-11-15
sge executor 3 2021-06-14 2022-01-19
Cannot install 9 2021-04-20 2021-12-08
Screenshots are not taken when using multiple windows 5 2015-10-08 2022-12-03
Opensupports_v4.9.0 not working . . blank page 3 2022-05-20 2022-11-26
[Bug]: Input buttons in chat have fixed width that cannot be changed 0 2022-10-04 2022-11-11
Scope Not Being Picked Up With Custom Pattern Matcher 2 2021-03-05 2022-09-24
Firmware 1.4.6_0012 unsupported 1 2021-11-20 2022-10-02
Clicking the interrupt button doesn't have any interactive response 1 2022-02-24 2022-11-03
在魔兽世界中,Rime不显示已输入的字符 12 2020-12-16 2022-11-03
Make the Mac application delete entries at just pressing "delete" or CMD + "delete" 5 2022-08-12 2022-09-09
Unlock with Hradware Key on macOS does not work 4 2022-08-13 2022-09-09
IssueEvent is missing payload for code review set of events 1 2022-08-23 2022-11-21
Cache doesn't work for $this->repository->paginate(); 1 2020-10-11 2022-12-03
awtk/3rd/stb/stb_truetype.h:1535: stbtt_FindGlyphIndex: Assertion `0' failed 1 2021-03-02 2022-11-22
Add ability to search for devices/VMs which do not have a given tag 4 2021-10-20 2022-10-14
Kubernetes-ingress chart should create ingressclass object if controller.ingressClass is not null 2 2021-06-22 2022-11-12
Unknown word CssSyntaxError in import inside script tag in vue file 6 2021-10-22 2022-11-21
"Error: connect ECONNREFUSED" when connecting through a proxy server 6 2014-01-07 2022-11-25
Geomaps's scale is hardly visible when using `ArcGIS MapServer` as layer type 0 2022-09-27 2022-09-21
Can't Import Separate .shp objects if a DateTime exists in the XML 1 2022-06-23 2022-11-14
Import georeferenced jp2 1 2022-06-29 2022-11-14
ERROR kuhl_m_sekurlsa_acquireLSA ; Key import 6 2021-06-22 2022-12-03
Simplify Dockerfiles by using dotnet-subset 1 2022-09-11 2022-11-08
why y is not the one-hot label encodings in the implementation? 1 2018-08-29 2022-10-08
[Support Request]: Are there any paid subscriptions ? 2 2021-12-14 2022-11-03
Large number of data points make "interval" plot un usable 0 2022-08-16 2022-11-13
绘制流程图的时候,删除标题会将整个节点删除,具体如下 3 2021-03-05 2022-10-18
关于MNN输出地址的strides是怎么定义的,在哪里修改? 0 2021-07-14 2022-10-20
[Enhancement] eventmesh go server add runtime grpc heatbeat processor 0 2022-09-16 2022-10-15
add HAKCRCF411D 2 2021-08-16 2021-12-27
NoneType' object is not iterable 0 2021-05-26 2022-12-03
[Q] Can set a conditional statement or something when wandb sweep? 2 2022-06-28 2022-11-19
Presta 1.7.6.8 Changing order status in hookActionOrderStatusUpdate ClassNotFoundException 0 2021-05-16 2021-09-29
Shadowsock bonding 0 2021-03-26 2022-01-13
Update README with badges and content 0 2017-01-26 2022-11-16
Task Viewing is not working 1 2022-11-03 2022-11-19
Ingester cleanup: remove `--ingester-address` querier CLI arg and supporting code 0 2022-06-30 2022-10-11
Rule Engine overview diagram incorrect 1 2021-12-15 2022-11-11