擅长:python、mysql、java
<p>您可以使用以下方法:</p>
<pre><code>In [5]: df = DataFrame({'A' : [5,6,3,4], 'B' : [1,2,3, 5]})
In [6]: df
Out[6]:
A B
0 5 1
1 6 2
2 3 3
3 4 5
In [7]: df[df['A'].isin([3, 6])]
Out[7]:
A B
1 6 2
2 3 3
</code></pre>
<p>顺便说一下,如果您使用笔记本电脑环境,最好使用:</p>
^{pr2}$
<p>编辑1:如果执行以下操作,会发生什么情况:</p>
<pre><code>values_list = df_ROI1['Subject'].unique()
if "577" in values_list:
print ("577 is in the dataframe and is a string")
elif 577 in values_list:
print ("577 is in the dataframe and is an integer")
else:
print ("577 is NOT in the dataframe")
</code></pre>
<p>编辑2:</p>
<p>所以你犯的错误是给算法一个字符串而不是一个整数。在</p>
<p>请尝试:</p>
<pre><code>df_ROI1 = df_ROI1[df_ROI1['Subject'].isin([577])] # Without the quotes around 577
df_ROI1.head(n=5)
</code></pre>