One - One Code All

Blog Content

pandas中dataframe筛选某列值是否在列表中isin

Python 统计学-科学计算   2015-05-10 15:19:11

pandas中dataframe筛选某列值是否在列表中isin


使用isin实现。

>>> n = 10
>>> df = pd.DataFrame(np.random.randint(n, size=(n, 2)), columns=list('bc'))
>>> df
   b  c
0  7  5
1  1  3
2  9  5
3  2  7
4  0  3
5  0  7
6  6  3
7  8  5
8  6  7
9  3  5
>>> df[df['b'].isin([7,3])]
   b  c
0  7  5
9  3  5



上一篇:Jupyter notebook添加目录导航
下一篇:padas的dataframe获取某行某列单个值loc与iloc

The minute you think of giving up, think of the reason why you held on so long.