-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
style apply of rows fails for subset list, but works for single row? #13222
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
Comments
I think this is functioning as designed. The docs lay it out here. The second item "A list (or series or numpy array)" should say "A list (or series or numpy array) is treated as a slice on the columns". To just style the first row you can use
That section in the docs should be updated though. |
I'm trying to highlight a subset of rows (not just the first one).
Fail with
How can I do this? |
OK, that one looks like it might be a bug. I'll take a closer look tonight. On May 18 2016, at 1:44 pm, Paul Perry <[email protected]> wrote:
|
While you are at it you might reconsider the interpretation that subset lists are only considered slices of columns. ("the second item"). It seems to me that the axis parameter already identifies whether it is an index or a column. It looks odd that axis=0 can only act on one row, and to do anything else requires a slice object. This renders the axis parameter useless. |
Ok, there's a few things going on...
def highlight(s):
return ['background-color: yellow' for _ in s] The I'll submit a PR tonight with some better documentation. Sorry it wasn't clearer to begin with, and thanks for the feedback. I'll think about how we can fail better here when the output shapes doesn't match, the current error message isn't great. |
Tom, that works, thank you. The doc had me believe the apply func worked the same on rows as columns. |
A little more on what I ran into: when the column names are integers I don't have a way of selecting them for styling. This may be unrelated to styling, but I can't solve this without renaming the columns as strings. I seem to do it positionally in the first example, but not the last one. Do you have a better suggestion? These work:
These fail:
Even though indexing by number works:
|
@paulperry your first two at least I assume that's your expected output. The last one (correctly) raises a KeyError. Only label-based indexing is allowed for |
@TomAugspurger yes! That's the right output. And I get the same good output you have in the environment I posted at the top of the thread, but not this one with the older pandas 0.17.1 :
The error:
Thank you! |
I forgot to mention that the Linux version above is the docker image of the dev environment for the declarativewidgets project and easily obtainable here: https://github.com/jupyter-incubator/declarativewidgets#develop |
Code Sample, a copy-pastable example if possible
The code appears to be applying it to the columns, not the rows, but passing a single value as the subset renders the table with the correct row highlighted.
Passing a bad row index (e.g. 3) also correctly fails with 'None of [[3]] are in the [index]'
df.style.apply(highlight, axis=1, subset=['Letter'])
works, butdf.style.apply(highlight, axis=1, subset=['Letter','Number'])
FailsExpected Output
output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Darwin
OS-release: 15.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
pandas: 0.18.0
nose: 1.3.7
pip: 8.1.2
setuptools: 20.3
Cython: 0.23.4
numpy: 1.10.4
scipy: 0.17.0
statsmodels: 0.6.1
xarray: None
IPython: 4.1.2
sphinx: 1.3.5
patsy: 0.4.0
dateutil: 2.5.1
pytz: 2016.2
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.5
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.8.4
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.39.0
The text was updated successfully, but these errors were encountered: