{"action":"created","issue":{"url":"https://api.github.com/repos/pydata/pandas/issues/13222","repository_url":"https://api.github.com/repos/pydata/pandas","labels_url":"https://api.github.com/repos/pydata/pandas/issues/13222/labels{/name}","comments_url":"https://api.github.com/repos/pydata/pandas/issues/13222/comments","events_url":"https://api.github.com/repos/pydata/pandas/issues/13222/events","html_url":"https://github.com/pydata/pandas/issues/13222","id":155560934,"number":13222,"title":"style apply of rows fails for subset list, but works for single row?","user":{"login":"paulperry","id":501736,"avatar_url":"https://avatars.githubusercontent.com/u/501736?v=3","gravatar_id":"","url":"https://api.github.com/users/paulperry","html_url":"https://github.com/paulperry","followers_url":"https://api.github.com/users/paulperry/followers","following_url":"https://api.github.com/users/paulperry/following{/other_user}","gists_url":"https://api.github.com/users/paulperry/gists{/gist_id}","starred_url":"https://api.github.com/users/paulperry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulperry/subscriptions","organizations_url":"https://api.github.com/users/paulperry/orgs","repos_url":"https://api.github.com/users/paulperry/repos","events_url":"https://api.github.com/users/paulperry/events{/privacy}","received_events_url":"https://api.github.com/users/paulperry/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pydata/pandas/labels/Visualization","name":"Visualization","color":"8AE234"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-18T17:42:27Z","updated_at":"2016-05-18T18:12:31Z","closed_at":null,"body":"#### Code Sample, a copy-pastable example if possible\r\n\r\n```\r\ndf = pd.DataFrame([[\"A\", 1],[\"B\", 2]], columns=[\"Letter\", \"Number\"])\r\ndef highlight(s):\r\n    return ['background-color: yellow']\r\ndf.style.apply(highlight, axis=0, subset=[0])\r\n\r\n---------------------------------------------------------------------------\r\nKeyError                                  Traceback (most recent call last)\r\n/Users/paulperry/anaconda/lib/python3.5/site-packages/IPython/core/formatters.py in __call__(self, obj)\r\n    341             method = _safe_get_formatter_method(obj, self.print_method)\r\n    342             if method is not None:\r\n--> 343                 return method()\r\n    344             return None\r\n    345         else:\r\n\r\n/Users/paulperry/anaconda/lib/python3.5/site-packages/pandas/core/style.py in _repr_html_(self)\r\n    163     def _repr_html_(self):\r\n    164         \"\"\"Hooks into Jupyter notebook rich display system.\"\"\"\r\n--> 165         return self.render()\r\n    166 \r\n    167     def _translate(self):\r\n\r\n/Users/paulperry/anaconda/lib/python3.5/site-packages/pandas/core/style.py in render(self)\r\n    356         the rendered HTML in the notebook.\r\n    357         \"\"\"\r\n--> 358         self._compute()\r\n    359         d = self._translate()\r\n    360         # filter out empty styles, every cell will have a class\r\n\r\n/Users/paulperry/anaconda/lib/python3.5/site-packages/pandas/core/style.py in _compute(self)\r\n    422         r = self\r\n    423         for func, args, kwargs in self._todo:\r\n--> 424             r = func(self)(*args, **kwargs)\r\n    425         return r\r\n    426 \r\n\r\n/Users/paulperry/anaconda/lib/python3.5/site-packages/pandas/core/style.py in _apply(self, func, axis, subset, **kwargs)\r\n    429         subset = _non_reducing_slice(subset)\r\n    430         if axis is not None:\r\n--> 431             result = self.data.loc[subset].apply(func, axis=axis, **kwargs)\r\n    432         else:\r\n    433             # like tee\r\n\r\n/Users/paulperry/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in __getitem__(self, key)\r\n   1282     def __getitem__(self, key):\r\n   1283         if type(key) is tuple:\r\n-> 1284             return self._getitem_tuple(key)\r\n   1285         else:\r\n   1286             return self._getitem_axis(key, axis=0)\r\n\r\n/Users/paulperry/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _getitem_tuple(self, tup)\r\n    783 \r\n    784         # no multi-index, so validate all of the indexers\r\n--> 785         self._has_valid_tuple(tup)\r\n    786 \r\n    787         # ugly hack for GH #836\r\n\r\n/Users/paulperry/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _has_valid_tuple(self, key)\r\n    136             if i >= self.obj.ndim:\r\n    137                 raise IndexingError('Too many indexers')\r\n--> 138             if not self._has_valid_type(k, i):\r\n    139                 raise ValueError(\"Location based indexing can only have [%s] \"\r\n    140                                  \"types\" % self._valid_types)\r\n\r\n/Users/paulperry/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _has_valid_type(self, key, axis)\r\n   1365 \r\n   1366                 raise KeyError(\"None of [%s] are in the [%s]\" %\r\n-> 1367                                (key, self.obj._get_axis_name(axis)))\r\n   1368 \r\n   1369             return True\r\n\r\nKeyError: 'None of [[0]] are in the [columns]'\r\n\r\nOut[16]:\r\n<pandas.core.style.Styler at 0x11ae32cf8>\r\n```\r\n\r\nThe 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.  \r\n\r\n```\r\ndf.style.apply(highlight, axis=0, subset=0)\r\n\r\nLetter\tNumber\r\n0\tA\t1    <- in html this row is highlighted yellow\r\n1\tB\t2\r\n```\r\nPassing a bad row index (e.g. 3) also correctly fails with 'None of [[3]] are in the [index]'\r\n\r\n```df.style.apply(highlight, axis=1, subset=['Letter'])``` works, but\r\n```df.style.apply(highlight, axis=1, subset=['Letter','Number'])``` Fails\r\n\r\n#### Expected Output\r\n\r\n```\r\ndf.style.apply(highlight, axis=0, subset=[0])\r\n\r\nLetter\tNumber\r\n0\tA\t1    <- in html this row should be highlighted yellow\r\n1\tB\t2\r\n\r\n```\r\n\r\n#### output of ``pd.show_versions()``\r\n\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit: None\r\npython: 3.5.1.final.0\r\npython-bits: 64\r\nOS: Darwin\r\nOS-release: 15.4.0\r\nmachine: x86_64\r\nprocessor: i386\r\nbyteorder: little\r\nLC_ALL: None\r\nLANG: en_US.UTF-8\r\n\r\npandas: 0.18.0\r\nnose: 1.3.7\r\npip: 8.1.2\r\nsetuptools: 20.3\r\nCython: 0.23.4\r\nnumpy: 1.10.4\r\nscipy: 0.17.0\r\nstatsmodels: 0.6.1\r\nxarray: None\r\nIPython: 4.1.2\r\nsphinx: 1.3.5\r\npatsy: 0.4.0\r\ndateutil: 2.5.1\r\npytz: 2016.2\r\nblosc: None\r\nbottleneck: 1.0.0\r\ntables: 3.2.2\r\nnumexpr: 2.5\r\nmatplotlib: 1.5.1\r\nopenpyxl: 2.3.2\r\nxlrd: 0.9.4\r\nxlwt: 1.0.0\r\nxlsxwriter: 0.8.4\r\nlxml: 3.6.0\r\nbs4: 4.4.1\r\nhtml5lib: None\r\nhttplib2: None\r\napiclient: None\r\nsqlalchemy: 1.0.12\r\npymysql: None\r\npsycopg2: None\r\njinja2: 2.8\r\nboto: 2.39.0\r\n"},"comment":{"url":"https://api.github.com/repos/pydata/pandas/issues/comments/220112076","html_url":"https://github.com/pydata/pandas/issues/13222#issuecomment-220112076","issue_url":"https://api.github.com/repos/pydata/pandas/issues/13222","id":220112076,"user":{"login":"TomAugspurger","id":1312546,"avatar_url":"https://avatars.githubusercontent.com/u/1312546?v=3","gravatar_id":"","url":"https://api.github.com/users/TomAugspurger","html_url":"https://github.com/TomAugspurger","followers_url":"https://api.github.com/users/TomAugspurger/followers","following_url":"https://api.github.com/users/TomAugspurger/following{/other_user}","gists_url":"https://api.github.com/users/TomAugspurger/gists{/gist_id}","starred_url":"https://api.github.com/users/TomAugspurger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomAugspurger/subscriptions","organizations_url":"https://api.github.com/users/TomAugspurger/orgs","repos_url":"https://api.github.com/users/TomAugspurger/repos","events_url":"https://api.github.com/users/TomAugspurger/events{/privacy}","received_events_url":"https://api.github.com/users/TomAugspurger/received_events","type":"User","site_admin":false},"created_at":"2016-05-18T18:12:30Z","updated_at":"2016-05-18T18:12:30Z","body":"I think this is functioning as designed.\r\n\r\nThe [docs](http://pandas.pydata.org/pandas-docs/version/0.18.1/style.html#Finer-Control:-Slicing) 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\".\r\n\r\nTo just style the first row you can use\r\n\r\n- `df.style.apply(highlight, subset=(0,))`  # note the comma to make it a tuple\r\n- `df.style.apply(highlight, subset=pd.IndexSlice[0, :])`\r\n\r\nThat section in the docs should be updated though."}}