Skip to content

ENH: Styler.highlight_null to accept subset argument #31345

Closed
@immaxchen

Description

@immaxchen

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame({"A": [0, None], "B": [0, None]})
df.style.highlight_null(null_color="red", subset=["A"])

out:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-c4119d081571> in <module>
----> 1 df.style.highlight_null(null_color="red", subset=["A"])

TypeError: highlight_null() got an unexpected keyword argument 'subset'

Problem description

Most of the Styler built-in methods support subset argument, except highlight_null.
I think it would be nice if we make it consistent with highlight_min and highlight_max etc.
This also improves the api completeness for missing values styling and formatting. (as discussed here)

Expected Output

Screenshot from 2020-01-27 23-16-43

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.8.1.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-862.14.4.el7.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.3
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 19.3.1
setuptools : 44.0.0.post20200106
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.11.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions