<p dir="auto">If I use <code class="notranslate">read_csv</code> to load a datafile with the default index_col, but the first column does not have unique values, it succeeds at first, but when I try to select rows later, I get <code class="notranslate">Exception: Index cannot contain duplicate values!</code>. This raises a couple of points:</p>
<ol dir="auto">
<li>Should the default be to use an index column? My data often doesn't have one. <a href="http://pinard.progiciels-bpi.ca/libR/library/base/html/read.table.html" rel="nofollow">Apparently</a> R takes the first column as an index if it doesn't have a header, and otherwise does an integer index.</li>
<li>Non-unique values should be detected when we're creating the index, and either leave that column as a regular column (falling back to an integer index), or raise an exception at that point.</li>
</ol>
<p dir="auto">Hello<br>
I am not sure, maybe this is the expected behaviour, but it was a big surprise for me (and a source of some bugs).</p>
<p dir="auto">As the title states, dropping rows (whether inplace or not) does not delete corresponding index entries (when the frame has a multiIndex). If one later uses index values directly it causes really unexpected behaviour.</p>
<p dir="auto">An obvious work-around is to reset index and re-build it, but it is not really elegant code...<br>
Simple example:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import pandas as pd
&gt;&gt;&gt; df = pd.DataFrame([['A', 'a', 1], ['B', 'b', 2], ['C', 'c', 3]], columns=['upper', 'lower', 'num'])
&gt;&gt;&gt; df = df.set_index(['upper', 'lower'])
&gt;&gt;&gt; df = df.drop('A')
&gt;&gt;&gt; df.index
MultiIndex(levels=[['A', 'B', 'C'], ['a', 'b', 'c']],
           labels=[[1, 2], [1, 2]],
           names=['upper', 'lower'])
&gt;&gt;&gt; df.index.levels[0]
Index(['A', 'B', 'C'], dtype='object', name='upper')"><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">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-s">'A'</span>, <span class="pl-s">'a'</span>, <span class="pl-c1">1</span>], [<span class="pl-s">'B'</span>, <span class="pl-s">'b'</span>, <span class="pl-c1">2</span>], [<span class="pl-s">'C'</span>, <span class="pl-s">'c'</span>, <span class="pl-c1">3</span>]], <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'upper'</span>, <span class="pl-s">'lower'</span>, <span class="pl-s">'num'</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">df</span>.<span class="pl-en">set_index</span>([<span class="pl-s">'upper'</span>, <span class="pl-s">'lower'</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">df</span>.<span class="pl-en">drop</span>(<span class="pl-s">'A'</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>.<span class="pl-s1">index</span>
<span class="pl-v">MultiIndex</span>(<span class="pl-s1">levels</span><span class="pl-c1">=</span>[[<span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>, <span class="pl-s">'C'</span>], [<span class="pl-s">'a'</span>, <span class="pl-s">'b'</span>, <span class="pl-s">'c'</span>]],
           <span class="pl-s1">labels</span><span class="pl-c1">=</span>[[<span class="pl-c1">1</span>, <span class="pl-c1">2</span>], [<span class="pl-c1">1</span>, <span class="pl-c1">2</span>]],
           <span class="pl-s1">names</span><span class="pl-c1">=</span>[<span class="pl-s">'upper'</span>, <span class="pl-s">'lower'</span>])
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>.<span class="pl-s1">index</span>.<span class="pl-s1">levels</span>[<span class="pl-c1">0</span>]
<span class="pl-v">Index</span>([<span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>, <span class="pl-s">'C'</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'object'</span>, <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'upper'</span>)</pre></div>
<p dir="auto">Even though the row was deleted correctly.</p>
<p dir="auto">show_versions():</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
INSTALLED VERSIONS
------------------
commit: None
python: 3.4.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.2.0-18-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.17.1
nose: 1.3.7
pip: None
setuptools: 18.4
Cython: 0.23.3
numpy: 1.10.1
scipy: 0.14.1
statsmodels: 0.6.1
IPython: 4.0.0
sphinx: 1.3.1
patsy: 0.4.1
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: None
numexpr: 2.4.4
matplotlib: 1.5.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.3.2
html5lib: 0.999
httplib2: 0.9
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
Jinja2: None
"><pre class="notranslate"><code class="notranslate">
INSTALLED VERSIONS
------------------
commit: None
python: 3.4.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.2.0-18-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.17.1
nose: 1.3.7
pip: None
setuptools: 18.4
Cython: 0.23.3
numpy: 1.10.1
scipy: 0.14.1
statsmodels: 0.6.1
IPython: 4.0.0
sphinx: 1.3.1
patsy: 0.4.1
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: None
numexpr: 2.4.4
matplotlib: 1.5.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.3.2
html5lib: 0.999
httplib2: 0.9
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
Jinja2: None

</code></pre></div>