-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: style.apply applies the style in subset, but it also reset the style elsewhere. #57470
Comments
Thanks for the report, confirmed on main. Further investigations and PRs to fix are welcome. cc @attack68 |
Hello I would be glad to work on it and fix it, |
take |
This isn't a bug at all. Every time you access |
The documentation clearly says returns a https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.style.html |
I am in the process of adding the in-place parameter to this, whilst it may not be a bug to be fixed, surely this could work as an additional feature? |
@Delengowski : You are right. def highlight_max(x, color): I'm still a bit confused by the API. I know it won't be changed, but it is not unnatural to think that df.style.apply should modify the style property of the dataframe. |
There is an entire guide for the Styler. Its design has been carefully put together and results in a very advanced manipulator that is decoupled from a DataFrame. What might seem unnatural now will seem natural, and more powerful later. |
Thanks! I missed that the methods were not being chained. 🤦 |
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
Issue Description
style.apply has a "subset" parameter. The documentation is not very explicit, but one expect that style.apply applies the style on the specified subset leaving the other cells style unchanged. This is not the case. style.apply applies the style on the specified subset, but it also reset the style elsewhere in the dataframe.
Expected Behavior
One value in green in column A and one value in red in column B (in a jupyter notebook)
It should be possible to apply a style on a subset, and then another style on another subset without losing the first styling.
Installed Versions
INSTALLED VERSIONS
commit : fd3f571
python : 3.11.6.final.0
python-bits : 64
OS : Linux
OS-release : 6.5.0-17-generic
Version : #17-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 11 14:01:59 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.0
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 68.1.2
pip : 23.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.3
IPython : 8.21.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.12.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: