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



上一篇:神经网络和支持向量机的优缺点
下一篇:鹧鸪天·天上人间酒最尊

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