<p dir="auto"><code class="notranslate">DataFrame.drop_duplicates()</code> does not properly handle array objects returned by <code class="notranslate">DataFrame.columns</code> (whether or not you use <code class="notranslate">DataFrame.columns.values</code> to get a NumPy array). If you compute</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="list(DataFrame.columns.values)"><pre class="notranslate"><code class="notranslate">list(DataFrame.columns.values)
</code></pre></div>
<p dir="auto">then it works, but this is needless overkill, especially when dealing with a large number of columns. Below is an example from IPython.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [71]: dfrm = pandas.DataFrame({&quot;A&quot;:[1,2,1,2,1,2], &quot;B&quot;:[3,4,3,4,3,4], &quot;C&quot;:[1,2,1,2,1,3]})

In [72]: dfrm
Out[72]:
   A  B  C
0  1  3  1
1  2  4  2
2  1  3  1
3  2  4  2
4  1  3  1
5  2  4  3

In [73]: dfrm.drop_duplicates(dfrm.columns)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (882, 0))
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (6442, 0))
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
/home/espears/&lt;ipython-input-73-bee9ee352073&gt; in &lt;module&gt;()
----&gt; 1 dfrm.drop_duplicates(dfrm.columns)

/opt/epd/7.2-1/lib/python2.7/site-packages/pandas/core/frame.pyc in drop_duplicates(self, cols, take_last)
   2254         deduplicated : DataFrame
   2255         &quot;&quot;&quot;
-&gt; 2256         duplicated = self.duplicated(cols, take_last=take_last)
   2257         return self[-duplicated]
   2258

/opt/epd/7.2-1/lib/python2.7/site-packages/pandas/core/frame.pyc in duplicated(self, cols, take_last)
   2283
   2284         duplicated = lib.duplicated(keys, take_last=take_last)
-&gt; 2285         return Series(duplicated, index=self.index)
   2286
   2287     #----------------------------------------------------------------------


/opt/epd/7.2-1/lib/python2.7/site-packages/pandas/core/series.pyc in __new__(cls, data, index, dtype, name, copy)
    286         else:
    287             subarr = subarr.view(Series)
--&gt; 288         subarr.index = index
    289         subarr.name = name
    290

/opt/epd/7.2-1/lib/python2.7/site-packages/pandas/_tseries.so in pandas._tseries.SeriesIndex.__set__ (pandas/src/tseries.c:73097)()

AssertionError: Index length did not match values

In [74]: dfrm.drop_duplicates(dfrm.columns.values)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (882, 0))
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (6442, 0))
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
/home/espears/&lt;ipython-input-74-cb96df701a9b&gt; in &lt;module&gt;()
----&gt; 1 dfrm.drop_duplicates(dfrm.columns.values)

/opt/epd/7.2-1/lib/python2.7/site-packages/pandas/core/frame.pyc in drop_duplicates(self, cols, take_last)
   2254         deduplicated : DataFrame
   2255         &quot;&quot;&quot;
-&gt; 2256         duplicated = self.duplicated(cols, take_last=take_last)
   2257         return self[-duplicated]
   2258

/opt/epd/7.2-1/lib/python2.7/site-packages/pandas/core/frame.pyc in duplicated(self, cols, take_last)
   2283
   2284         duplicated = lib.duplicated(keys, take_last=take_last)
-&gt; 2285         return Series(duplicated, index=self.index)
   2286
   2287     #----------------------------------------------------------------------


/opt/epd/7.2-1/lib/python2.7/site-packages/pandas/core/series.pyc in __new__(cls, data, index, dtype, name, copy)
    286         else:
    287             subarr = subarr.view(Series)
--&gt; 288         subarr.index = index
    289         subarr.name = name
    290

/opt/epd/7.2-1/lib/python2.7/site-packages/pandas/_tseries.so in pandas._tseries.SeriesIndex.__set__ (pandas/src/tseries.c:73097)()

AssertionError: Index length did not match values

In [75]: dfrm.columns.values
Out[75]: array([A, B, C], dtype=object)

In [76]: list(dfrm.columns.values)
Out[76]: ['A', 'B', 'C']

In [77]: dfrm.drop_duplicates(list(dfrm.columns.values))
Out[77]:
   A  B  C
0  1  3  1
1  2  4  2
5  2  4  3"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">71</span>]: <span class="pl-s1">dfrm</span> <span class="pl-c1">=</span> <span class="pl-s1">pandas</span>.<span class="pl-v">DataFrame</span>({<span class="pl-s">"A"</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-c1">1</span>,<span class="pl-c1">2</span>], <span class="pl-s">"B"</span>:[<span class="pl-c1">3</span>,<span class="pl-c1">4</span>,<span class="pl-c1">3</span>,<span class="pl-c1">4</span>,<span class="pl-c1">3</span>,<span class="pl-c1">4</span>], <span class="pl-s">"C"</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-c1">1</span>,<span class="pl-c1">3</span>]})

<span class="pl-v">In</span> [<span class="pl-c1">72</span>]: <span class="pl-s1">dfrm</span>
<span class="pl-v">Out</span>[<span class="pl-c1">72</span>]:
   <span class="pl-v">A</span>  <span class="pl-v">B</span>  <span class="pl-v">C</span>
<span class="pl-c1">0</span>  <span class="pl-c1">1</span>  <span class="pl-c1">3</span>  <span class="pl-c1">1</span>
<span class="pl-c1">1</span>  <span class="pl-c1">2</span>  <span class="pl-c1">4</span>  <span class="pl-c1">2</span>
<span class="pl-c1">2</span>  <span class="pl-c1">1</span>  <span class="pl-c1">3</span>  <span class="pl-c1">1</span>
<span class="pl-c1">3</span>  <span class="pl-c1">2</span>  <span class="pl-c1">4</span>  <span class="pl-c1">2</span>
<span class="pl-c1">4</span>  <span class="pl-c1">1</span>  <span class="pl-c1">3</span>  <span class="pl-c1">1</span>
<span class="pl-c1">5</span>  <span class="pl-c1">2</span>  <span class="pl-c1">4</span>  <span class="pl-c1">3</span>

<span class="pl-v">In</span> [<span class="pl-c1">73</span>]: <span class="pl-s1">dfrm</span>.<span class="pl-en">drop_duplicates</span>(<span class="pl-s1">dfrm</span>.<span class="pl-s1">columns</span>)
<span class="pl-v">ERROR</span>: <span class="pl-v">An</span> <span class="pl-s1">unexpected</span> <span class="pl-s1">error</span> <span class="pl-s1">occurred</span> <span class="pl-k">while</span> <span class="pl-s1">tokenizing</span> <span class="pl-s1">input</span>
<span class="pl-v">The</span> <span class="pl-s1">following</span> <span class="pl-s1">traceback</span> <span class="pl-s1">may</span> <span class="pl-s1">be</span> <span class="pl-s1">corrupted</span> <span class="pl-c1">or</span> <span class="pl-s1">invalid</span>
<span class="pl-v">The</span> <span class="pl-s1">error</span> <span class="pl-s1">message</span> <span class="pl-c1">is</span>: (<span class="pl-s">'EOF in multi-line statement'</span>, (<span class="pl-c1">882</span>, <span class="pl-c1">0</span>))
<span class="pl-v">ERROR</span>: <span class="pl-v">An</span> <span class="pl-s1">unexpected</span> <span class="pl-s1">error</span> <span class="pl-s1">occurred</span> <span class="pl-k">while</span> <span class="pl-s1">tokenizing</span> <span class="pl-s1">input</span>
<span class="pl-v">The</span> <span class="pl-s1">following</span> <span class="pl-s1">traceback</span> <span class="pl-s1">may</span> <span class="pl-s1">be</span> <span class="pl-s1">corrupted</span> <span class="pl-c1">or</span> <span class="pl-s1">invalid</span>
<span class="pl-v">The</span> <span class="pl-s1">error</span> <span class="pl-s1">message</span> <span class="pl-c1">is</span>: (<span class="pl-s">'EOF in multi-line statement'</span>, (<span class="pl-c1">6442</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">AssertionError</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">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">espears</span><span class="pl-c1">/</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">73</span><span class="pl-c1">-</span><span class="pl-s1">bee9ee352073</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">dfrm</span>.<span class="pl-en">drop_duplicates</span>(<span class="pl-s1">dfrm</span>.<span class="pl-s1">columns</span>)

<span class="pl-c1">/</span><span class="pl-s1">opt</span><span class="pl-c1">/</span><span class="pl-s1">epd</span><span class="pl-c1">/</span><span class="pl-c1">7.2</span><span class="pl-c1">-</span><span class="pl-c1">1</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">frame</span>.<span class="pl-s1">pyc</span> <span class="pl-c1">in</span> <span class="pl-en">drop_duplicates</span>(<span class="pl-s1">self</span>, <span class="pl-s1">cols</span>, <span class="pl-s1">take_last</span>)
   <span class="pl-c1">2254</span>         <span class="pl-s1">deduplicated</span> : <span class="pl-v">DataFrame</span>
   <span class="pl-c1">2255</span>         <span class="pl-s">"""</span>
<span class="pl-s">-&gt; 2256         duplicated = self.duplicated(cols, take_last=take_last)</span>
<span class="pl-s">   2257         return self[-duplicated]</span>
<span class="pl-s">   2258</span>
<span class="pl-s"></span>
<span class="pl-s">/opt/epd/7.2-1/lib/python2.7/site-packages/pandas/core/frame.pyc in duplicated(self, cols, take_last)</span>
<span class="pl-s">   2283</span>
<span class="pl-s">   2284         duplicated = lib.duplicated(keys, take_last=take_last)</span>
<span class="pl-s">-&gt; 2285         return Series(duplicated, index=self.index)</span>
<span class="pl-s">   2286</span>
<span class="pl-s">   2287     #----------------------------------------------------------------------</span>
<span class="pl-s"></span>
<span class="pl-s"></span>
<span class="pl-s">/opt/epd/7.2-1/lib/python2.7/site-packages/pandas/core/series.pyc in __new__(cls, data, index, dtype, name, copy)</span>
<span class="pl-s">    286         else:</span>
<span class="pl-s">    287             subarr = subarr.view(Series)</span>
<span class="pl-s">--&gt; 288         subarr.index = index</span>
<span class="pl-s">    289         subarr.name = name</span>
<span class="pl-s">    290</span>
<span class="pl-s"></span>
<span class="pl-s">/opt/epd/7.2-1/lib/python2.7/site-packages/pandas/_tseries.so in pandas._tseries.SeriesIndex.__set__ (pandas/src/tseries.c:73097)()</span>
<span class="pl-s"></span>
<span class="pl-s">AssertionError: Index length did not match values</span>
<span class="pl-s"></span>
<span class="pl-s">In [74]: dfrm.drop_duplicates(dfrm.columns.values)</span>
<span class="pl-s">ERROR: An unexpected error occurred while tokenizing input</span>
<span class="pl-s">The following traceback may be corrupted or invalid</span>
<span class="pl-s">The error message is: ('EOF in multi-line statement', (882, 0))</span>
<span class="pl-s">ERROR: An unexpected error occurred while tokenizing input</span>
<span class="pl-s">The following traceback may be corrupted or invalid</span>
<span class="pl-s">The error message is: ('EOF in multi-line statement', (6442, 0))</span>
<span class="pl-s">---------------------------------------------------------------------------</span>
<span class="pl-s">AssertionError                            Traceback (most recent call last)</span>
<span class="pl-s">/home/espears/&lt;ipython-input-74-cb96df701a9b&gt; in &lt;module&gt;()</span>
<span class="pl-s">----&gt; 1 dfrm.drop_duplicates(dfrm.columns.values)</span>
<span class="pl-s"></span>
<span class="pl-s">/opt/epd/7.2-1/lib/python2.7/site-packages/pandas/core/frame.pyc in drop_duplicates(self, cols, take_last)</span>
<span class="pl-s">   2254         deduplicated : DataFrame</span>
<span class="pl-s">   2255         """</span>
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">2256</span>         <span class="pl-s1">duplicated</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">duplicated</span>(<span class="pl-s1">cols</span>, <span class="pl-s1">take_last</span><span class="pl-c1">=</span><span class="pl-s1">take_last</span>)
   <span class="pl-c1">2257</span>         <span class="pl-k">return</span> <span class="pl-s1">self</span>[<span class="pl-c1">-</span><span class="pl-s1">duplicated</span>]
   <span class="pl-c1">2258</span>

<span class="pl-c1">/</span><span class="pl-s1">opt</span><span class="pl-c1">/</span><span class="pl-s1">epd</span><span class="pl-c1">/</span><span class="pl-c1">7.2</span><span class="pl-c1">-</span><span class="pl-c1">1</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">frame</span>.<span class="pl-s1">pyc</span> <span class="pl-c1">in</span> <span class="pl-en">duplicated</span>(<span class="pl-s1">self</span>, <span class="pl-s1">cols</span>, <span class="pl-s1">take_last</span>)
   <span class="pl-c1">2283</span>
   <span class="pl-c1">2284</span>         <span class="pl-s1">duplicated</span> <span class="pl-c1">=</span> <span class="pl-s1">lib</span>.<span class="pl-en">duplicated</span>(<span class="pl-s1">keys</span>, <span class="pl-s1">take_last</span><span class="pl-c1">=</span><span class="pl-s1">take_last</span>)
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">2285</span>         <span class="pl-s1">return</span> <span class="pl-v">Series</span>(<span class="pl-s1">duplicated</span>, <span class="pl-s1">index</span><span class="pl-c1">=</span><span class="pl-s1">self</span>.<span class="pl-s1">index</span>)
   <span class="pl-c1">2286</span>
   <span class="pl-c1">2287</span>     <span class="pl-c">#----------------------------------------------------------------------</span>


<span class="pl-c1">/</span><span class="pl-s1">opt</span><span class="pl-c1">/</span><span class="pl-s1">epd</span><span class="pl-c1">/</span><span class="pl-c1">7.2</span><span class="pl-c1">-</span><span class="pl-c1">1</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">series</span>.<span class="pl-s1">pyc</span> <span class="pl-c1">in</span> <span class="pl-en">__new__</span>(<span class="pl-s1">cls</span>, <span class="pl-s1">data</span>, <span class="pl-s1">index</span>, <span class="pl-s1">dtype</span>, <span class="pl-s1">name</span>, <span class="pl-s1">copy</span>)
    <span class="pl-c1">286</span>         <span class="pl-s1">else</span>:
    <span class="pl-c1">287</span>             <span class="pl-s1">subarr</span> <span class="pl-c1">=</span> <span class="pl-s1">subarr</span>.<span class="pl-en">view</span>(<span class="pl-v">Series</span>)
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">288</span>         <span class="pl-s1">subarr</span>.<span class="pl-s1">index</span> <span class="pl-c1">=</span> <span class="pl-s1">index</span>
    <span class="pl-c1">289</span>         <span class="pl-s1">subarr</span>.<span class="pl-s1">name</span> <span class="pl-c1">=</span> <span class="pl-s1">name</span>
    <span class="pl-c1">290</span>

<span class="pl-c1">/</span><span class="pl-s1">opt</span><span class="pl-c1">/</span><span class="pl-s1">epd</span><span class="pl-c1">/</span><span class="pl-c1">7.2</span><span class="pl-c1">-</span><span class="pl-c1">1</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">_tseries</span>.<span class="pl-s1">so</span> <span class="pl-c1">in</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">_tseries</span>.<span class="pl-v">SeriesIndex</span>.<span class="pl-en">__set__</span> (<span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">src</span><span class="pl-c1">/</span><span class="pl-s1">tseries</span>.<span class="pl-s1">c</span>:<span class="pl-c1">73097</span>)()

<span class="pl-v">AssertionError</span>: <span class="pl-v">Index</span> <span class="pl-s1">length</span> <span class="pl-s1">did</span> <span class="pl-c1">not</span> <span class="pl-s1">match</span> <span class="pl-s1">values</span>

<span class="pl-v">In</span> [<span class="pl-c1">75</span>]: <span class="pl-s1">dfrm</span>.<span class="pl-s1">columns</span>.<span class="pl-s1">values</span>
<span class="pl-v">Out</span>[<span class="pl-c1">75</span>]: <span class="pl-en">array</span>([<span class="pl-v">A</span>, <span class="pl-v">B</span>, <span class="pl-v">C</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">object</span>)

<span class="pl-v">In</span> [<span class="pl-c1">76</span>]: <span class="pl-en">list</span>(<span class="pl-s1">dfrm</span>.<span class="pl-s1">columns</span>.<span class="pl-s1">values</span>)
<span class="pl-v">Out</span>[<span class="pl-c1">76</span>]: [<span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>, <span class="pl-s">'C'</span>]

<span class="pl-v">In</span> [<span class="pl-c1">77</span>]: <span class="pl-s1">dfrm</span>.<span class="pl-en">drop_duplicates</span>(<span class="pl-en">list</span>(<span class="pl-s1">dfrm</span>.<span class="pl-s1">columns</span>.<span class="pl-s1">values</span>))
<span class="pl-v">Out</span>[<span class="pl-c1">77</span>]:
   <span class="pl-v">A</span>  <span class="pl-v">B</span>  <span class="pl-v">C</span>
<span class="pl-c1">0</span>  <span class="pl-c1">1</span>  <span class="pl-c1">3</span>  <span class="pl-c1">1</span>
<span class="pl-c1">1</span>  <span class="pl-c1">2</span>  <span class="pl-c1">4</span>  <span class="pl-c1">2</span>
<span class="pl-c1">5</span>  <span class="pl-c1">2</span>  <span class="pl-c1">4</span>  <span class="pl-c1">3</span></pre></div>
<p dir="auto">FWIW:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [91]: pandas.__version__
Out[91]: '0.7.3'"><pre class="notranslate"><code class="notranslate">In [91]: pandas.__version__
Out[91]: '0.7.3'
</code></pre></div>
<p dir="auto">This was suggested by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/MaximilianR/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/MaximilianR">@MaximilianR</a> <a href="https://github.com/pandas-dev/pandas/issues/12392#issuecomment-186308548" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/12392/hovercard">here</a>, but <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jorisvandenbossche/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jorisvandenbossche">@jorisvandenbossche</a> (rightly) <a href="https://github.com/pandas-dev/pandas/issues/12392#issuecomment-186451899" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/12392/hovercard">proposed</a> to discuss separately.</p>
<p dir="auto">This is related to the discussion on <code class="notranslate">.rename</code> and <code class="notranslate">.rename_axis</code>'s signatures (see above), but touches a different issue. Currently, these two functions are confusing not just because they do the same thing, but also because they (each) do two <em>different</em> things (renaming axis/object name, and relabeling), and because they do not do the most obvious thing (relabeling by passing a list-like - since a list-like is assumed to refer to multiple names for a <code class="notranslate">MultiIndex</code>' levels).</p>
<p dir="auto">My proposal is the following:</p>
<ul dir="auto">
<li>add a new method <code class="notranslate">.relabel</code>, which changes the <em>content</em> of the axis, as in</li>
</ul>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="df.relabel(['l1', 'l2', 'l3']) # changes df.index labels - assuming df.index is flat
df.relabel([['l1a', 'l1b', 'l1c'], [...], [...]]) # changes df.index labels - assuming df.index has 3 levels
df.relabel(a_dict) # again, changes the index labels, analogously to what df.rename(a_dict) currently does"><pre class="notranslate"><span class="pl-s1">df</span>.<span class="pl-en">relabel</span>([<span class="pl-s">'l1'</span>, <span class="pl-s">'l2'</span>, <span class="pl-s">'l3'</span>]) <span class="pl-c"># changes df.index labels - assuming df.index is flat</span>
<span class="pl-s1">df</span>.<span class="pl-en">relabel</span>([[<span class="pl-s">'l1a'</span>, <span class="pl-s">'l1b'</span>, <span class="pl-s">'l1c'</span>], [...], [...]]) <span class="pl-c"># changes df.index labels - assuming df.index has 3 levels</span>
<span class="pl-s1">df</span>.<span class="pl-en">relabel</span>(<span class="pl-s1">a_dict</span>) <span class="pl-c"># again, changes the index labels, analogously to what df.rename(a_dict) currently does</span></pre></div>
<ul dir="auto">
<li>deprecate the use of <code class="notranslate">.rename</code> and <code class="notranslate">.rename_index</code> for doing the same operation, that is when the <code class="notranslate">index</code> or <code class="notranslate">mapper</code> argument (respectively) is a callable or dict-like; keep them (or, even better, keep one and deprecate the other) for changing only index names</li>
</ul>
<p dir="auto">Whether the signature of <code class="notranslate">.relabel</code> should follow the <code class="notranslate">axis=</code> or <code class="notranslate">index=</code>, <code class="notranslate">column=</code> standard will depend from the outcome of the discussion about <code class="notranslate">rename</code> and <code class="notranslate">rename_index</code> (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="134767386" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/12392" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/12392/hovercard" href="https://github.com/pandas-dev/pandas/issues/12392">#12392</a>).</p>