Description
-
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.
Code Sample, a copy-pastable example
A short example adjusted from the one in issue #29975 (which appeared to be the closest bug to this one, unless I missed something)
>>> df = pd.DataFrame({'a': [1, pd.NA, 2]})
>>> df
>>> 'zzzz' in df.to_csv(na_rep='zzzz')
True
>>> 'zzzz' in df.to_html(na_rep='zzzz')
False
Problem description
pd.NA seems to be ignored by the na_rep
in to_html()
. In the HTML, pd.NA shows up as <NA>
.
The na_rep
works fine for pd.NA in to_csv()
and works fine for NaNs in to_html()
:
>>> df = pd.DataFrame({'a': [1, float('nan'), 2]})
>>> 'zzzz' in df.to_csv(na_rep='zzzz')
True
>>> 'zzzz' in df.to_html(na_rep='zzzz')
True
Expected Output
I'd expect pd.NA to be represented by the na_rep
in the output of to_html()
.
Output of pd.show_versions()
commit : None
python : 3.7.7.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-7642-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.3
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.1.3.post20200330
Cython : 0.29.15
pytest : 5.4.1
hypothesis : 5.8.3
sphinx : 2.4.4
blosc : None
feather : None
xlsxwriter : 1.2.8
lxml.etree : 4.5.0
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.13.0
pandas_datareader: None
bs4 : 4.8.2
bottleneck : 1.3.2
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : 3.1.3
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.4.1
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.15
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.2.8
numba : 0.48.0