some misunderstanding about `pandas.series.drop()`
<p>I want to drop some specific rows in a <code>pandas.DataFrame</code>, while it seems that <code>pandas.Series.drop()</code>.What I have tried is as follows:</p>

<pre><code>In[1]:
a_pd = pd.DataFrame(np.array([[1,2,3], [2,'?','x'],['s','d',4]]), columns=list('abc'))
a_pd
Out[1]:
    a   b   c
    0   1   2   3
    1   2   ?   x
    2   s   d   4

In[2]:
a_pd['b'].drop(a_pd['b'] == '?', inplace=True)
a_pd
out[2]:
    a   b   c
0   1   2   3
1   2   ?   x
2   s   d   4
</code></pre>

<p>Why it is the same <code>a_pd</code>???
Then I tried the <code>pandas.DataFrame.drop</code>, the result is more amazing:</p>

<pre><code>In[3]:
b_pd = a_pd.drop(a_pd['b'] == '?')
out[3]:
a   b   c
1   2   ?   x
2   s   d   4
</code></pre>

<p>What happened? I cannot believe my eyes. Although I can easily choose the what I want by simply using <code>a_pd[a_pd['b'] != '?']</code>, I still want to try <code>drop()</code>.</p>

<p>pandas.drop() works on the labels associated with the row you want do delete, which in this case is 0, 1, or 2.  So you can delete the middle row by </p>

<pre><code>a_pd.drop([1])
</code></pre>

<p>returns</p>

<pre><code>   a  b  c
0  1  2  3
2  s  d  4
</code></pre>

<p>Similarly, for the Series version of .drop(), will remove a row from the series.  </p>

<pre><code>a_pd['b'].drop([1])
</code></pre>

<p>returns</p>

<pre><code>0  2
2  d
</code></pre>

<p>When you use the selection </p>

<pre><code>a_pd['b'] == '?'
</code></pre>

<p>you get an array of boolean values</p>

<pre><code>0    False
1    True
2    False
Name:  b, dtype: bool
</code></pre>

<p>and the result of </p>

<pre><code>a_pd.drop(a_pd['b'] == '?')
</code></pre>

<p>is the same as </p>

<pre><code>a_pd.drop([False, True, False])
</code></pre>

<p>But now is where things are not as expected, rather than apply a drop where the boolean value is True, this array is treated as an array of integer indices to drop namely</p>

<pre><code>a_pd.drop([0, 1, 0])
</code></pre>

<p>And thus the result is a removal of the first two rows (the first row is removed twice)</p>

<pre><code>   a  b  c
2  s  d  4
</code></pre>

<p>At least that is how it works on my version of pandas</p>

<pre><code>pandas.__version__
$&gt; u'0.17.1'
</code></pre>

python pandas