Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] 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 ```
Comment From: attack68
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")
Comment From: attack68
Comment From: saiwing-yeung
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?
Comment From: attack68
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
Comment From: saiwing-yeung
That's fair, thanks for the tips and looking into this.