擅长:python、mysql、java
<p>您可以将<a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow noreferrer">^{<cd1>}</a>与<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isin.html" rel="nofollow noreferrer">^{<cd2>}</a>一起使用,以反转布尔掩码<code>~</code>:</p>
<pre><code>idx = df.index[~df['id'].isin(L)].tolist()
print (idx)
[1, 2, 4, 5]
</code></pre>
<p>然后<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop.html" rel="nofollow noreferrer">^{<cd4>}</a>:</p>
^{pr2}$
<p>备选方案:</p>
<pre><code>df1 = df[df['id'].isin(L)]
print (df1)
id value
0 14 122
3 17 490
6 20 323
</code></pre>