<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [1]: import pandas as pd

In [2]: pd.__version__
Out[2]: '0.23.0rc2'

In [3]: dates = [pd.Timestamp(&quot;2016-01-0%d 12:00:00&quot; % i, tz='US/Pacific')
   ...:          for i in range(1, 5)]
   ...: df = pd.DataFrame({'A': ['a', 'b'] * 2, 'B': dates})
   ...: grouped = df.groupby('A')
   ...:

In [4]: df
Out[4]:
   A                         B
0  a 2016-01-01 12:00:00-08:00
1  b 2016-01-02 12:00:00-08:00
2  a 2016-01-03 12:00:00-08:00
3  b 2016-01-04 12:00:00-08:00

In [5]: grouped.apply(lambda x: x.iloc[0])[0]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   3062             try:
-&gt; 3063                 return self._engine.get_loc(key)
   3064             except KeyError:

C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5720)()
    138
--&gt; 139     cpdef get_loc(self, object val):
    140         if is_definitely_invalid_key(val):

C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5566)()
    160         try:
--&gt; 161             return self.mapping.get_item(val)
    162         except (TypeError, ValueError):

C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:22442)()
   1491
-&gt; 1492     cpdef get_item(self, object val):
   1493         cdef khiter_t k

C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:22396)()
   1499         else:
-&gt; 1500             raise KeyError(val)
   1501

KeyError: 0

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
&lt;ipython-input-5-2b16555d6e05&gt; in &lt;module&gt;()
----&gt; 1 grouped.apply(lambda x: x.iloc[0])[0]

C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\core\frame.py in __getitem__(self, key)
   2685             return self._getitem_multilevel(key)
   2686         else:
-&gt; 2687             return self._getitem_column(key)
   2688
   2689     def _getitem_column(self, key):

C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\core\frame.py in _getitem_column(self, key)
   2692         # get column
   2693         if self.columns.is_unique:
-&gt; 2694             return self._get_item_cache(key)
   2695
   2696         # duplicate columns &amp; possible reduce dimensionality

C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\core\generic.py in _get_item_cache(self, item)
   2485         res = cache.get(item)
   2486         if res is None:
-&gt; 2487             values = self._data.get(item)
   2488             res = self._box_item_values(item, values)
   2489             cache[item] = res

C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\core\internals.py in get(self, item, fastpath)
   4113
   4114             if not isna(item):
-&gt; 4115                 loc = self.items.get_loc(item)
   4116             else:
   4117                 indexer = np.arange(len(self.items))[isna(self.items)]

C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   3063                 return self._engine.get_loc(key)
   3064             except KeyError:
-&gt; 3065                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   3066
   3067         indexer = self.get_indexer([key], method=method, tolerance=tolerance)

C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5720)()
    137             util.set_value_at(arr, loc, value)
    138
--&gt; 139     cpdef get_loc(self, object val):
    140         if is_definitely_invalid_key(val):
    141             raise TypeError(&quot;'{val}' is an invalid key&quot;.format(val=val))


C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5566)()
    159
    160         try:
--&gt; 161             return self.mapping.get_item(val)
    162         except (TypeError, ValueError):
    163             raise KeyError(val)

C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:22442)()
   1490                                        sizeof(uint32_t)) # flags
   1491
-&gt; 1492     cpdef get_item(self, object val):
   1493         cdef khiter_t k
   1494         if val != val or val is None:

C:\EclipseWorkspaces\LiClipseWorkspace\pandas-dev\pandas36\pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:22396)()
   1498             return self.table.vals[k]
   1499         else:
-&gt; 1500             raise KeyError(val)
   1501
   1502     cpdef set_item(self, object key, Py_ssize_t val):

KeyError: 0"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">1</span>]: <span class="pl-s1">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>

<span class="pl-v">In</span> [<span class="pl-c1">2</span>]: <span class="pl-s1">pd</span>.<span class="pl-s1">__version__</span>
<span class="pl-v">Out</span>[<span class="pl-c1">2</span>]: <span class="pl-s">'0.23.0rc2'</span>

<span class="pl-v">In</span> [<span class="pl-c1">3</span>]: <span class="pl-s1">dates</span> <span class="pl-c1">=</span> [<span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s">"2016-01-0%d 12:00:00"</span> <span class="pl-c1">%</span> <span class="pl-s1">i</span>, <span class="pl-s1">tz</span><span class="pl-c1">=</span><span class="pl-s">'US/Pacific'</span>)
   ...:          <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">1</span>, <span class="pl-c1">5</span>)]
   ...: <span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({<span class="pl-s">'A'</span>: [<span class="pl-s">'a'</span>, <span class="pl-s">'b'</span>] <span class="pl-c1">*</span> <span class="pl-c1">2</span>, <span class="pl-s">'B'</span>: <span class="pl-s1">dates</span>})
   ...: <span class="pl-s1">grouped</span> <span class="pl-c1">=</span> <span class="pl-s1">df</span>.<span class="pl-en">groupby</span>(<span class="pl-s">'A'</span>)
   ...:

<span class="pl-v">In</span> [<span class="pl-c1">4</span>]: <span class="pl-s1">df</span>
<span class="pl-v">Out</span>[<span class="pl-c1">4</span>]:
   <span class="pl-v">A</span>                         <span class="pl-v">B</span>
<span class="pl-c1">0</span>  <span class="pl-s1">a</span> <span class="pl-c1">2016</span><span class="pl-c1">-</span><span class="pl-c1">01</span><span class="pl-c1">-</span><span class="pl-c1">01</span> <span class="pl-c1">12</span>:<span class="pl-c1">00</span>:<span class="pl-c1">00</span><span class="pl-c1">-</span><span class="pl-c1">08</span>:<span class="pl-c1">00</span>
<span class="pl-c1">1</span>  <span class="pl-s1">b</span> <span class="pl-c1">2016</span><span class="pl-c1">-</span><span class="pl-c1">01</span><span class="pl-c1">-</span><span class="pl-c1">02</span> <span class="pl-c1">12</span>:<span class="pl-c1">00</span>:<span class="pl-c1">00</span><span class="pl-c1">-</span><span class="pl-c1">08</span>:<span class="pl-c1">00</span>
<span class="pl-c1">2</span>  <span class="pl-s1">a</span> <span class="pl-c1">2016</span><span class="pl-c1">-</span><span class="pl-c1">01</span><span class="pl-c1">-</span><span class="pl-c1">03</span> <span class="pl-c1">12</span>:<span class="pl-c1">00</span>:<span class="pl-c1">00</span><span class="pl-c1">-</span><span class="pl-c1">08</span>:<span class="pl-c1">00</span>
<span class="pl-c1">3</span>  <span class="pl-s1">b</span> <span class="pl-c1">2016</span><span class="pl-c1">-</span><span class="pl-c1">01</span><span class="pl-c1">-</span><span class="pl-c1">04</span> <span class="pl-c1">12</span>:<span class="pl-c1">00</span>:<span class="pl-c1">00</span><span class="pl-c1">-</span><span class="pl-c1">08</span>:<span class="pl-c1">00</span>

<span class="pl-v">In</span> [<span class="pl-c1">5</span>]: <span class="pl-s1">grouped</span>.<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span>.<span class="pl-s1">iloc</span>[<span class="pl-c1">0</span>])[<span class="pl-c1">0</span>]
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span>
<span class="pl-v">KeyError</span>                                  <span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>)
<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\c<span class="pl-s1">ore</span>\i<span class="pl-s1">ndexes</span>\b<span class="pl-s1">ase</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">get_loc</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>, <span class="pl-s1">method</span>, <span class="pl-s1">tolerance</span>)
   <span class="pl-c1">3062</span>             <span class="pl-k">try</span>:
<span class="pl-c1">-&gt;</span> <span class="pl-c1">3063</span>                 <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-s1">_engine</span>.<span class="pl-en">get_loc</span>(<span class="pl-s1">key</span>)
   <span class="pl-c1">3064</span>             <span class="pl-k">except</span> <span class="pl-v">KeyError</span>:

<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\_<span class="pl-s1">libs</span>\i<span class="pl-s1">ndex</span>.<span class="pl-s1">pyx</span> <span class="pl-c1">in</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">_libs</span>.<span class="pl-s1">index</span>.<span class="pl-v">IndexEngine</span>.<span class="pl-en">get_loc</span> (<span class="pl-s1">pandas</span>\_<span class="pl-s1">libs</span>\i<span class="pl-s1">ndex</span>.<span class="pl-s1">c</span>:<span class="pl-c1">5720</span>)()
    <span class="pl-c1">138</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">139</span>     <span class="pl-s1">cpdef</span> <span class="pl-en">get_loc</span>(<span class="pl-s1">self</span>, <span class="pl-s1">object</span> <span class="pl-s1">val</span>):
    <span class="pl-c1">140</span>         <span class="pl-k">if</span> <span class="pl-en">is_definitely_invalid_key</span>(<span class="pl-s1">val</span>):

<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\_<span class="pl-s1">libs</span>\i<span class="pl-s1">ndex</span>.<span class="pl-s1">pyx</span> <span class="pl-c1">in</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">_libs</span>.<span class="pl-s1">index</span>.<span class="pl-v">IndexEngine</span>.<span class="pl-en">get_loc</span> (<span class="pl-s1">pandas</span>\_<span class="pl-s1">libs</span>\i<span class="pl-s1">ndex</span>.<span class="pl-s1">c</span>:<span class="pl-c1">5566</span>)()
    <span class="pl-c1">160</span>         <span class="pl-k">try</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">161</span>             <span class="pl-s1">return</span> <span class="pl-s1">self</span>.<span class="pl-s1">mapping</span>.<span class="pl-en">get_item</span>(<span class="pl-s1">val</span>)
    <span class="pl-c1">162</span>         <span class="pl-en">except</span> (<span class="pl-v">TypeError</span>, <span class="pl-v">ValueError</span>):

<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\_<span class="pl-s1">libs</span>\h<span class="pl-s1">ashtable_class_helper</span>.<span class="pl-s1">pxi</span> <span class="pl-c1">in</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">_libs</span>.<span class="pl-s1">hashtable</span>.<span class="pl-v">PyObjectHashTable</span>.<span class="pl-en">get_item</span> (<span class="pl-s1">pandas</span>\_<span class="pl-s1">libs</span>\h<span class="pl-s1">ashtable</span>.<span class="pl-s1">c</span>:<span class="pl-c1">22442</span>)()
   <span class="pl-c1">1491</span>
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1492</span>     <span class="pl-s1">cpdef</span> <span class="pl-en">get_item</span>(<span class="pl-s1">self</span>, <span class="pl-s1">object</span> <span class="pl-s1">val</span>):
   <span class="pl-c1">1493</span>         <span class="pl-s1">cdef</span> <span class="pl-s1">khiter_t</span> <span class="pl-s1">k</span>

<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\_<span class="pl-s1">libs</span>\h<span class="pl-s1">ashtable_class_helper</span>.<span class="pl-s1">pxi</span> <span class="pl-c1">in</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">_libs</span>.<span class="pl-s1">hashtable</span>.<span class="pl-v">PyObjectHashTable</span>.<span class="pl-en">get_item</span> (<span class="pl-s1">pandas</span>\_<span class="pl-s1">libs</span>\h<span class="pl-s1">ashtable</span>.<span class="pl-s1">c</span>:<span class="pl-c1">22396</span>)()
   <span class="pl-c1">1499</span>         <span class="pl-k">else</span>:
<span class="pl-c1">-&gt;</span> <span class="pl-c1">1500</span>             <span class="pl-s1">raise</span> <span class="pl-v">KeyError</span>(<span class="pl-s1">val</span>)
   <span class="pl-c1">1501</span>

<span class="pl-v">KeyError</span>: <span class="pl-c1">0</span>

<span class="pl-v">During</span> <span class="pl-s1">handling</span> <span class="pl-s1">of</span> <span class="pl-s1">the</span> <span class="pl-s1">above</span> <span class="pl-s1">exception</span>, <span class="pl-s1">another</span> <span class="pl-s1">exception</span> <span class="pl-s1">occurred</span>:

<span class="pl-v">KeyError</span>                                  <span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>)
<span class="pl-c1">&lt;</span><span class="pl-s1">ipython</span><span class="pl-c1">-</span><span class="pl-s1">input</span><span class="pl-c1">-</span><span class="pl-c1">5</span><span class="pl-c1">-</span><span class="pl-c1">2</span><span class="pl-s1">b16555d6e05</span><span class="pl-c1">&gt;</span> <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>()
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-s1">grouped</span>.<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span>.<span class="pl-s1">iloc</span>[<span class="pl-c1">0</span>])[<span class="pl-c1">0</span>]

<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\c<span class="pl-s1">ore</span>\f<span class="pl-s1">rame</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">__getitem__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>)
   <span class="pl-c1">2685</span>             <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-en">_getitem_multilevel</span>(<span class="pl-s1">key</span>)
   <span class="pl-c1">2686</span>         <span class="pl-s1">else</span>:
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">2687</span>             <span class="pl-s1">return</span> <span class="pl-s1">self</span>.<span class="pl-en">_getitem_column</span>(<span class="pl-s1">key</span>)
   <span class="pl-c1">2688</span>
   <span class="pl-c1">2689</span>     <span class="pl-k">def</span> <span class="pl-en">_getitem_column</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>):

<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\c<span class="pl-s1">ore</span>\f<span class="pl-s1">rame</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">_getitem_column</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>)
   <span class="pl-c1">2692</span>         <span class="pl-c"># get column</span>
   <span class="pl-c1">2693</span>         <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">columns</span>.<span class="pl-s1">is_unique</span>:
<span class="pl-c1">-&gt;</span> <span class="pl-c1">2694</span>             <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-en">_get_item_cache</span>(<span class="pl-s1">key</span>)
   <span class="pl-c1">2695</span>
   <span class="pl-c1">2696</span>         <span class="pl-c"># duplicate columns &amp; possible reduce dimensionality</span>

<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\c<span class="pl-s1">ore</span>\g<span class="pl-s1">eneric</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">_get_item_cache</span>(<span class="pl-s1">self</span>, <span class="pl-s1">item</span>)
   <span class="pl-c1">2485</span>         <span class="pl-s1">res</span> <span class="pl-c1">=</span> <span class="pl-s1">cache</span>.<span class="pl-en">get</span>(<span class="pl-s1">item</span>)
   <span class="pl-c1">2486</span>         <span class="pl-k">if</span> <span class="pl-s1">res</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>:
<span class="pl-c1">-&gt;</span> <span class="pl-c1">2487</span>             <span class="pl-s1">values</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">_data</span>.<span class="pl-en">get</span>(<span class="pl-s1">item</span>)
   <span class="pl-c1">2488</span>             <span class="pl-s1">res</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">_box_item_values</span>(<span class="pl-s1">item</span>, <span class="pl-s1">values</span>)
   <span class="pl-c1">2489</span>             <span class="pl-s1">cache</span>[<span class="pl-s1">item</span>] <span class="pl-c1">=</span> <span class="pl-s1">res</span>

<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\c<span class="pl-s1">ore</span>\i<span class="pl-s1">nternals</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">get</span>(<span class="pl-s1">self</span>, <span class="pl-s1">item</span>, <span class="pl-s1">fastpath</span>)
   <span class="pl-c1">4113</span>
   <span class="pl-c1">4114</span>             <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-en">isna</span>(<span class="pl-s1">item</span>):
<span class="pl-c1">-&gt;</span> <span class="pl-c1">4115</span>                 <span class="pl-s1">loc</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">items</span>.<span class="pl-en">get_loc</span>(<span class="pl-s1">item</span>)
   <span class="pl-c1">4116</span>             <span class="pl-k">else</span>:
   <span class="pl-c1">4117</span>                 <span class="pl-s1">indexer</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-en">len</span>(<span class="pl-s1">self</span>.<span class="pl-s1">items</span>))[<span class="pl-en">isna</span>(<span class="pl-s1">self</span>.<span class="pl-s1">items</span>)]

<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\c<span class="pl-s1">ore</span>\i<span class="pl-s1">ndexes</span>\b<span class="pl-s1">ase</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">get_loc</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>, <span class="pl-s1">method</span>, <span class="pl-s1">tolerance</span>)
   <span class="pl-c1">3063</span>                 <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-s1">_engine</span>.<span class="pl-en">get_loc</span>(<span class="pl-s1">key</span>)
   <span class="pl-c1">3064</span>             <span class="pl-k">except</span> <span class="pl-v">KeyError</span>:
<span class="pl-c1">-&gt;</span> <span class="pl-c1">3065</span>                 <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-s1">_engine</span>.<span class="pl-en">get_loc</span>(<span class="pl-s1">self</span>.<span class="pl-en">_maybe_cast_indexer</span>(<span class="pl-s1">key</span>))
   <span class="pl-c1">3066</span>
   <span class="pl-c1">3067</span>         <span class="pl-s1">indexer</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">get_indexer</span>([<span class="pl-s1">key</span>], <span class="pl-s1">method</span><span class="pl-c1">=</span><span class="pl-s1">method</span>, <span class="pl-s1">tolerance</span><span class="pl-c1">=</span><span class="pl-s1">tolerance</span>)

<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\_<span class="pl-s1">libs</span>\i<span class="pl-s1">ndex</span>.<span class="pl-s1">pyx</span> <span class="pl-c1">in</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">_libs</span>.<span class="pl-s1">index</span>.<span class="pl-v">IndexEngine</span>.<span class="pl-en">get_loc</span> (<span class="pl-s1">pandas</span>\_<span class="pl-s1">libs</span>\i<span class="pl-s1">ndex</span>.<span class="pl-s1">c</span>:<span class="pl-c1">5720</span>)()
    <span class="pl-c1">137</span>             <span class="pl-s1">util</span>.<span class="pl-en">set_value_at</span>(<span class="pl-s1">arr</span>, <span class="pl-s1">loc</span>, <span class="pl-s1">value</span>)
    <span class="pl-c1">138</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">139</span>     <span class="pl-s1">cpdef</span> <span class="pl-en">get_loc</span>(<span class="pl-s1">self</span>, <span class="pl-s1">object</span> <span class="pl-s1">val</span>):
    <span class="pl-c1">140</span>         <span class="pl-k">if</span> <span class="pl-en">is_definitely_invalid_key</span>(<span class="pl-s1">val</span>):
    <span class="pl-c1">141</span>             <span class="pl-s1">raise</span> <span class="pl-v">TypeError</span>(<span class="pl-s">"'{val}' is an invalid key"</span>.<span class="pl-en">format</span>(<span class="pl-s1">val</span><span class="pl-c1">=</span><span class="pl-s1">val</span>))


<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\_<span class="pl-s1">libs</span>\i<span class="pl-s1">ndex</span>.<span class="pl-s1">pyx</span> <span class="pl-c1">in</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">_libs</span>.<span class="pl-s1">index</span>.<span class="pl-v">IndexEngine</span>.<span class="pl-en">get_loc</span> (<span class="pl-s1">pandas</span>\_<span class="pl-s1">libs</span>\i<span class="pl-s1">ndex</span>.<span class="pl-s1">c</span>:<span class="pl-c1">5566</span>)()
    <span class="pl-c1">159</span>
    <span class="pl-c1">160</span>         <span class="pl-k">try</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">161</span>             <span class="pl-s1">return</span> <span class="pl-s1">self</span>.<span class="pl-s1">mapping</span>.<span class="pl-en">get_item</span>(<span class="pl-s1">val</span>)
    <span class="pl-c1">162</span>         <span class="pl-en">except</span> (<span class="pl-v">TypeError</span>, <span class="pl-v">ValueError</span>):
    <span class="pl-c1">163</span>             <span class="pl-s1">raise</span> <span class="pl-v">KeyError</span>(<span class="pl-s1">val</span>)

<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\_<span class="pl-s1">libs</span>\h<span class="pl-s1">ashtable_class_helper</span>.<span class="pl-s1">pxi</span> <span class="pl-c1">in</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">_libs</span>.<span class="pl-s1">hashtable</span>.<span class="pl-v">PyObjectHashTable</span>.<span class="pl-en">get_item</span> (<span class="pl-s1">pandas</span>\_<span class="pl-s1">libs</span>\h<span class="pl-s1">ashtable</span>.<span class="pl-s1">c</span>:<span class="pl-c1">22442</span>)()
   <span class="pl-c1">1490</span>                                        <span class="pl-s1">sizeof</span>(<span class="pl-s1">uint32_t</span>)) <span class="pl-c"># flags</span>
   <span class="pl-c1">1491</span>
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1492</span>     <span class="pl-s1">cpdef</span> <span class="pl-en">get_item</span>(<span class="pl-s1">self</span>, <span class="pl-s1">object</span> <span class="pl-s1">val</span>):
   <span class="pl-c1">1493</span>         <span class="pl-s1">cdef</span> <span class="pl-s1">khiter_t</span> <span class="pl-s1">k</span>
   <span class="pl-c1">1494</span>         <span class="pl-k">if</span> <span class="pl-s1">val</span> <span class="pl-c1">!=</span> <span class="pl-s1">val</span> <span class="pl-c1">or</span> <span class="pl-s1">val</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>:

<span class="pl-v">C</span>:\E<span class="pl-s1">clipseWorkspaces</span>\L<span class="pl-s1">iClipseWorkspace</span>\p<span class="pl-s1">andas</span><span class="pl-c1">-</span><span class="pl-s1">dev</span>\p<span class="pl-s1">andas36</span>\p<span class="pl-s1">andas</span>\_<span class="pl-s1">libs</span>\h<span class="pl-s1">ashtable_class_helper</span>.<span class="pl-s1">pxi</span> <span class="pl-c1">in</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">_libs</span>.<span class="pl-s1">hashtable</span>.<span class="pl-v">PyObjectHashTable</span>.<span class="pl-en">get_item</span> (<span class="pl-s1">pandas</span>\_<span class="pl-s1">libs</span>\h<span class="pl-s1">ashtable</span>.<span class="pl-s1">c</span>:<span class="pl-c1">22396</span>)()
   <span class="pl-c1">1498</span>             <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-s1">table</span>.<span class="pl-s1">vals</span>[<span class="pl-s1">k</span>]
   <span class="pl-c1">1499</span>         <span class="pl-k">else</span>:
<span class="pl-c1">-&gt;</span> <span class="pl-c1">1500</span>             <span class="pl-s1">raise</span> <span class="pl-v">KeyError</span>(<span class="pl-s1">val</span>)
   <span class="pl-c1">1501</span>
   <span class="pl-c1">1502</span>     <span class="pl-s1">cpdef</span> <span class="pl-en">set_item</span>(<span class="pl-s1">self</span>, <span class="pl-s1">object</span> <span class="pl-s1">key</span>, <span class="pl-v">Py_ssize_t</span> <span class="pl-s1">val</span>):

<span class="pl-v">KeyError</span>: <span class="pl-c1">0</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">Related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="320236174" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/20949" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/20949/hovercard" href="https://github.com/pandas-dev/pandas/issues/20949">#20949</a> (and moved from there at request).</p>
<p dir="auto">Note that if you do the following, it works:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [6]: grouped.nth(0)['B'].iloc[0]
Out[6]: Timestamp('2016-01-01 12:00:00-0800', tz='US/Pacific')

In [7]: grouped.apply(lambda x: x.iloc[0])[0]
Out[7]: Timestamp('2016-01-01 12:00:00-0800', tz='US/Pacific')"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">6</span>]: <span class="pl-s1">grouped</span>.<span class="pl-en">nth</span>(<span class="pl-c1">0</span>)[<span class="pl-s">'B'</span>].<span class="pl-s1">iloc</span>[<span class="pl-c1">0</span>]
<span class="pl-v">Out</span>[<span class="pl-c1">6</span>]: <span class="pl-v">Timestamp</span>(<span class="pl-s">'2016-01-01 12:00:00-0800'</span>, <span class="pl-s1">tz</span><span class="pl-c1">=</span><span class="pl-s">'US/Pacific'</span>)

<span class="pl-v">In</span> [<span class="pl-c1">7</span>]: <span class="pl-s1">grouped</span>.<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span>.<span class="pl-s1">iloc</span>[<span class="pl-c1">0</span>])[<span class="pl-c1">0</span>]
<span class="pl-v">Out</span>[<span class="pl-c1">7</span>]: <span class="pl-v">Timestamp</span>(<span class="pl-s">'2016-01-01 12:00:00-0800'</span>, <span class="pl-s1">tz</span><span class="pl-c1">=</span><span class="pl-s">'US/Pacific'</span>)</pre></div>
<p dir="auto">So doing one operation (in this case <code class="notranslate">nth</code>) prior to the <code class="notranslate">apply</code> then makes the <code class="notranslate">apply</code> work.</p>
<h4 dir="auto">Expected Output</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [5]: grouped.apply(lambda x: x.iloc[0])[0]
Out[5]: Timestamp('2016-01-01 12:00:00-0800', tz='US/Pacific')"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">5</span>]: <span class="pl-s1">grouped</span>.<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span>.<span class="pl-s1">iloc</span>[<span class="pl-c1">0</span>])[<span class="pl-c1">0</span>]
<span class="pl-v">Out</span>[<span class="pl-c1">5</span>]: <span class="pl-v">Timestamp</span>(<span class="pl-s">'2016-01-01 12:00:00-0800'</span>, <span class="pl-s1">tz</span><span class="pl-c1">=</span><span class="pl-s">'US/Pacific'</span>)</pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pandas-dev/pandas/commit/b02c69ac7309ccf63a17471b25475bf0c0ebe3c3/hovercard" href="https://github.com/pandas-dev/pandas/commit/b02c69ac7309ccf63a17471b25475bf0c0ebe3c3"><tt>b02c69a</tt></a><br>
python: 3.6.4.final.0<br>
python-bits: 64<br>
OS: Windows<br>
OS-release: 10<br>
machine: AMD64<br>
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: None<br>
LOCALE: None.None</p>
<p dir="auto">pandas: 0.23.0rc2<br>
pytest: 3.4.0<br>
pip: 9.0.1<br>
setuptools: 38.5.1<br>
Cython: 0.25.1<br>
numpy: 1.14.1<br>
scipy: 1.0.0<br>
pyarrow: 0.8.0<br>
xarray: None<br>
IPython: 6.2.1<br>
sphinx: 1.7.1<br>
patsy: 0.5.0<br>
dateutil: 2.6.1<br>
pytz: 2018.3<br>
blosc: 1.5.1<br>
bottleneck: 1.2.1<br>
tables: 3.4.2<br>
numexpr: 2.6.4<br>
feather: None<br>
matplotlib: 2.2.0<br>
openpyxl: 2.5.0<br>
xlrd: 1.1.0<br>
xlwt: 1.3.0<br>
xlsxwriter: 1.0.2<br>
lxml: 4.1.1<br>
bs4: 4.6.0<br>
html5lib: 1.0.1<br>
sqlalchemy: 1.2.5<br>
pymysql: 0.8.0<br>
psycopg2: None<br>
jinja2: 2.10<br>
s3fs: 0.1.3<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<h4 dir="auto">Bug description</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In[1]: import pandas as pd
In[2]: df = pd.DataFrame({&quot;key&quot;: [&quot;a&quot;, &quot;a&quot;, &quot;b&quot;, &quot;b&quot;, &quot;b&quot;],
                   &quot;value_str&quot;: [&quot;u1&quot;, &quot;u2&quot;, &quot;u3&quot;, &quot;u4&quot;, &quot;u5&quot;],
                   &quot;value_int&quot;: range(5)})
In[3]: df
Out[3]:
  key value_str  value_int
0   a        u1          0
1   a        u2          1
2   b        u3          2
3   b        u4          3
4   b        u5          4"><pre class="notranslate"><span class="pl-v">In</span>[<span class="pl-c1">1</span>]: <span class="pl-s1">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-v">In</span>[<span class="pl-c1">2</span>]: <span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({<span class="pl-s">"key"</span>: [<span class="pl-s">"a"</span>, <span class="pl-s">"a"</span>, <span class="pl-s">"b"</span>, <span class="pl-s">"b"</span>, <span class="pl-s">"b"</span>],
                   <span class="pl-s">"value_str"</span>: [<span class="pl-s">"u1"</span>, <span class="pl-s">"u2"</span>, <span class="pl-s">"u3"</span>, <span class="pl-s">"u4"</span>, <span class="pl-s">"u5"</span>],
                   <span class="pl-s">"value_int"</span>: <span class="pl-en">range</span>(<span class="pl-c1">5</span>)})
<span class="pl-v">In</span>[<span class="pl-c1">3</span>]: <span class="pl-s1">df</span>
<span class="pl-v">Out</span>[<span class="pl-c1">3</span>]:
  <span class="pl-s1">key</span> <span class="pl-s1">value_str</span>  <span class="pl-s1">value_int</span>
<span class="pl-c1">0</span>   <span class="pl-s1">a</span>        <span class="pl-s1">u1</span>          <span class="pl-c1">0</span>
<span class="pl-c1">1</span>   <span class="pl-s1">a</span>        <span class="pl-s1">u2</span>          <span class="pl-c1">1</span>
<span class="pl-c1">2</span>   <span class="pl-s1">b</span>        <span class="pl-s1">u3</span>          <span class="pl-c1">2</span>
<span class="pl-c1">3</span>   <span class="pl-s1">b</span>        <span class="pl-s1">u4</span>          <span class="pl-c1">3</span>
<span class="pl-c1">4</span>   <span class="pl-s1">b</span>        <span class="pl-s1">u5</span>          <span class="pl-c1">4</span></pre></div>
<p dir="auto">when groupby "key" and rank "value_str", error presents</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In[4]: df.groupby(&quot;key&quot;)[&quot;value_str&quot;].rank()  # error
Out[4]: 
Traceback (most recent call last):
  File &quot;/Users/wangqian/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py&quot;, line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File &quot;&lt;ipython-input-9-5357c8abb14f&gt;&quot;, line 1, in &lt;module&gt;
    df.groupby(&quot;key&quot;)[&quot;value_str&quot;].rank()
  File &quot;/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py&quot;, line 1906, in rank
    na_option=na_option, pct=pct, axis=axis)
  File &quot;/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py&quot;, line 1025, in _cython_transform
    **kwargs)
  File &quot;/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py&quot;, line 2630, in transform
    return self._cython_operation('transform', values, how, axis, **kwargs)
  File &quot;/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py&quot;, line 2590, in _cython_operation
    **kwargs)
  File &quot;/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py&quot;, line 2664, in _transform
    transform_func(result, values, comp_ids, is_datetimelike, **kwargs)
  File &quot;/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py&quot;, line 2479, in wrapper
    return f(afunc, *args, **kwargs)
  File &quot;/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py&quot;, line 2431, in &lt;lambda&gt;
    kwargs.get('na_option', 'keep')
TypeError: 'NoneType' object is not callable
"><pre class="notranslate"><code class="notranslate">In[4]: df.groupby("key")["value_str"].rank()  # error
Out[4]: 
Traceback (most recent call last):
  File "/Users/wangqian/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "&lt;ipython-input-9-5357c8abb14f&gt;", line 1, in &lt;module&gt;
    df.groupby("key")["value_str"].rank()
  File "/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py", line 1906, in rank
    na_option=na_option, pct=pct, axis=axis)
  File "/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py", line 1025, in _cython_transform
    **kwargs)
  File "/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py", line 2630, in transform
    return self._cython_operation('transform', values, how, axis, **kwargs)
  File "/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py", line 2590, in _cython_operation
    **kwargs)
  File "/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py", line 2664, in _transform
    transform_func(result, values, comp_ids, is_datetimelike, **kwargs)
  File "/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py", line 2479, in wrapper
    return f(afunc, *args, **kwargs)
  File "/Users/wangqian/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/groupby.py", line 2431, in &lt;lambda&gt;
    kwargs.get('na_option', 'keep')
TypeError: 'NoneType' object is not callable

</code></pre></div>
<p dir="auto">but, if group by "key" and rank "value_int", the error doesn't present:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In[10]: df.groupby(&quot;key&quot;)[&quot;value_int&quot;].rank()

Out[10]: 
0    1.0
1    2.0
2    1.0
3    2.0
4    3.0
Name: value_int, dtype: float64"><pre class="notranslate"><code class="notranslate">In[10]: df.groupby("key")["value_int"].rank()

Out[10]: 
0    1.0
1    2.0
2    1.0
3    2.0
4    3.0
Name: value_int, dtype: float64
</code></pre></div>
<p dir="auto">if we just rank "value_str", the error dosen't present either:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In[11]: df[&quot;value_str&quot;].rank()

Out[11]: 
0    1.0
1    2.0
2    3.0
3    4.0
4    5.0
Name: value_str, dtype: float64"><pre class="notranslate"><code class="notranslate">In[11]: df["value_str"].rank()

Out[11]: 
0    1.0
1    2.0
2    3.0
3    4.0
4    5.0
Name: value_str, dtype: float64
</code></pre></div>