How do I use within / in operator in a Pandas DataFrame?
This question already has an answer here:
Use the Series.isin()
method to check if a series value is in a list of values. In your case -
df[df['House'].isin([1, 2, 3, 4, 6, 7, 8, 9, 10, 13, 17, 18, 20, 21, 23, 26, 28, 30, 34, 46, 57, 58, 61, 86, 89, 102, 121, 156])]
Example -
In [77]: df
Out[77]:
A B
0 1 5
1 2 6
2 3 7
3 4 8
In [78]: df[df['A'].isin([1,2])]
Out[78]:
A B
0 1 5
1 2 6
链接地址: http://www.djcxy.com/p/28106.html