<p dir="auto">I'm really sorry if this is a duplicate issue of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="11842447" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/2997" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/2997/hovercard" href="https://github.com/pandas-dev/pandas/issues/2997">#2997</a>, but it seems to me that this is a little bit different. Here the <code class="notranslate">.ix</code> when getting a value interprets the integer as label, and when setting a value it interprets it as a positional index.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; import pandas as pd
&gt;&gt;&gt; df = pd.DataFrame(np.arange(16).reshape((4, 4)),
                      columns=['a', 'b', 8, 'c'],
                      index=['e', 7, 'f', 'g'])
&gt;&gt;&gt; df
    a   b   8   c
e   0   1   2   3
7   4   5   6   7
f   8   9  10  11
g  12  13  14  15
&gt;&gt;&gt; df.ix['e', 8]
2
&gt;&gt;&gt; df.ix['e', 8] = 42
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;pandas/core/indexing.py&quot;, line 90, in __setitem__
    self._setitem_with_indexer(indexer, value)
  File &quot;pandas/core/indexing.py&quot;, line 190, in _setitem_with_indexer
    values[indexer] = value
IndexError: index 8 is out of bounds for axis 1 with size 4
&gt;&gt;&gt; df.loc['e', 8] = 42
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;pandas/core/indexing.py&quot;, line 90, in __setitem__
    self._setitem_with_indexer(indexer, value)
  File &quot;pandas/core/indexing.py&quot;, line 190, in _setitem_with_indexer
    values[indexer] = value
IndexError: index 8 is out of bounds for axis 1 with size 4"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</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-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">16</span>).<span class="pl-en">reshape</span>((<span class="pl-c1">4</span>, <span class="pl-c1">4</span>)),
                      <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'a'</span>, <span class="pl-s">'b'</span>, <span class="pl-c1">8</span>, <span class="pl-s">'c'</span>],
                      <span class="pl-s1">index</span><span class="pl-c1">=</span>[<span class="pl-s">'e'</span>, <span class="pl-c1">7</span>, <span class="pl-s">'f'</span>, <span class="pl-s">'g'</span>])
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>
    <span class="pl-s1">a</span>   <span class="pl-s1">b</span>   <span class="pl-c1">8</span>   <span class="pl-s1">c</span>
<span class="pl-s1">e</span>   <span class="pl-c1">0</span>   <span class="pl-c1">1</span>   <span class="pl-c1">2</span>   <span class="pl-c1">3</span>
<span class="pl-c1">7</span>   <span class="pl-c1">4</span>   <span class="pl-c1">5</span>   <span class="pl-c1">6</span>   <span class="pl-c1">7</span>
<span class="pl-s1">f</span>   <span class="pl-c1">8</span>   <span class="pl-c1">9</span>  <span class="pl-c1">10</span>  <span class="pl-c1">11</span>
<span class="pl-s1">g</span>  <span class="pl-c1">12</span>  <span class="pl-c1">13</span>  <span class="pl-c1">14</span>  <span class="pl-c1">15</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>.<span class="pl-s1">ix</span>[<span class="pl-s">'e'</span>, <span class="pl-c1">8</span>]
<span class="pl-c1">2</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>.<span class="pl-s1">ix</span>[<span class="pl-s">'e'</span>, <span class="pl-c1">8</span>] <span class="pl-c1">=</span> <span class="pl-c1">42</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">File</span> <span class="pl-s">"&lt;stdin&gt;"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1</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-v">File</span> <span class="pl-s">"pandas/core/indexing.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">90</span>, <span class="pl-s1">in</span> <span class="pl-s1">__setitem__</span>
    <span class="pl-s1">self</span>.<span class="pl-en">_setitem_with_indexer</span>(<span class="pl-s1">indexer</span>, <span class="pl-s1">value</span>)
  <span class="pl-v">File</span> <span class="pl-s">"pandas/core/indexing.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">190</span>, <span class="pl-s1">in</span> <span class="pl-s1">_setitem_with_indexer</span>
    <span class="pl-s1">values</span>[<span class="pl-s1">indexer</span>] <span class="pl-c1">=</span> <span class="pl-s1">value</span>
<span class="pl-v">IndexError</span>: <span class="pl-s1">index</span> <span class="pl-c1">8</span> <span class="pl-c1">is</span> <span class="pl-s1">out</span> <span class="pl-s1">of</span> <span class="pl-s1">bounds</span> <span class="pl-s1">for</span> <span class="pl-s1">axis</span> <span class="pl-c1">1</span> <span class="pl-k">with</span> <span class="pl-s1">size</span> <span class="pl-c1">4</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>.<span class="pl-s1">loc</span>[<span class="pl-s">'e'</span>, <span class="pl-c1">8</span>] <span class="pl-c1">=</span> <span class="pl-c1">42</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">File</span> <span class="pl-s">"&lt;stdin&gt;"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1</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-v">File</span> <span class="pl-s">"pandas/core/indexing.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">90</span>, <span class="pl-s1">in</span> <span class="pl-s1">__setitem__</span>
    <span class="pl-s1">self</span>.<span class="pl-en">_setitem_with_indexer</span>(<span class="pl-s1">indexer</span>, <span class="pl-s1">value</span>)
  <span class="pl-v">File</span> <span class="pl-s">"pandas/core/indexing.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">190</span>, <span class="pl-s1">in</span> <span class="pl-s1">_setitem_with_indexer</span>
    <span class="pl-s1">values</span>[<span class="pl-s1">indexer</span>] <span class="pl-c1">=</span> <span class="pl-s1">value</span>
<span class="pl-v">IndexError</span>: <span class="pl-s1">index</span> <span class="pl-c1">8</span> <span class="pl-c1">is</span> <span class="pl-s1">out</span> <span class="pl-s1">of</span> <span class="pl-s1">bounds</span> <span class="pl-s1">for</span> <span class="pl-s1">axis</span> <span class="pl-c1">1</span> <span class="pl-k">with</span> <span class="pl-s1">size</span> <span class="pl-c1">4</span></pre></div>
<p dir="auto">I see this issue with the 0.12 version and also with the latest git checkout.</p>
<p dir="auto"><em>Update: <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jreback/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jreback">@jreback</a> noticed that the <code class="notranslate">.loc</code> is not working either.</em></p>
<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="python -c &quot;import pandas as pd; df = pd.DataFrame(dict(a=[1, 1, 2, 3], b=[1, 2, 3, 4])); print(df.nsmallest(2, 'a'))&quot;"><pre class="notranslate"><code class="notranslate">python -c "import pandas as pd; df = pd.DataFrame(dict(a=[1, 1, 2, 3], b=[1, 2, 3, 4])); print(df.nsmallest(2, 'a'))"
</code></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">When using nlargest/nsmallest and the n largest / smallest values are identical, the method seems to return the dataframe concatenated with the filtered version of itself.<br>
Furthermore if all values are identical, you get the full dataframe concatenated with itself, regardless of the choice of <code class="notranslate">n</code></p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">Not really sure, I guess in the example above you should simply get a dataframe that looks like this<br>
<code class="notranslate">pd.DataFrame(dict(a=[1, 1], b=[1, 2]))</code><br>
however if you were to have<br>
<code class="notranslate"> df = pd.DataFrame(dict(a=[1, 1, 1, 1], b=[1, 2, 3, 4]))</code><br>
and asked for<br>
<code class="notranslate">df.nlargest(2, 'a')</code> you should again get<br>
<code class="notranslate">pd.DataFrame(dict(a=[1, 1], b=[1, 2]))</code></p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Linux
OS-release: 4.8.0-34-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_IE.UTF-8
LOCALE: None.None
<p dir="auto">pandas: 0.19.2<br>
nose: 1.3.7<br>
pip: 9.0.1<br>
setuptools: 28.3.0<br>
Cython: 0.23.4<br>
numpy: 1.12.0<br>
scipy: 0.16.1<br>
statsmodels: 0.6.1<br>
xarray: None<br>
IPython: None<br>
sphinx: 1.3.1<br>
patsy: 0.4.1<br>
dateutil: 2.6.0<br>
pytz: 2016.10<br>
blosc: None<br>
bottleneck: None<br>
tables: 3.2.0<br>
numexpr: 2.4.6<br>
matplotlib: 1.5.0<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: None<br>
httplib2: 0.9.2<br>
apiclient: None<br>
sqlalchemy: 1.0.9<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.8<br>
boto: 2.38.0<br>
pandas_datareader: None</p>
</details>