python isin函数_pandas中isin()函数及其逆函数使用

pandas中isin()函数及其逆函数使用

发布时间:2018-05-27 21:11,

浏览次数:2021

, 标签:

pandas

isin

我使用这个函数就是用来清洗数据,删选过滤掉DataFrame中一些行。

布尔索引

这里你需要知道DateFrame中布尔索引这个东西,可以用满足布尔条件的列值来过滤数据,如下

>>> df=pd.DataFrame(np.random.randn(4,4),columns=[A,B,C,D]) >>> df A B

C D0 -0.018330 2.093506 -0.086293 -2.150479 1 0.104931 -0.271810 -0.054599

0.361612 2 0.590216 0.218049 0.157213 0.643540 3 -0.254449 -0.593278 -0.150455 -

0.244485 >>> df.A>0#布尔索引 0 False 1 True 2 True 3 False Name: A, dtype: bool

#布尔索引应用 >>> df[df.A>0] A B C D 1 0.104931 -0.271810 -0.054599 0.361612 2

0.590216 0.218049 0.157213 0.643540 >>>

isin()

添加一列E

>>> df[E]=[a,a,c,b

pandas中isin()函数及其逆函数使用 发布时间:2018-05-27 21:11, 浏览次数:2021 , 标签: pandas isin 我使用这个函数就是用来清洗数据,删选过滤掉DataFrame中一些行。 布尔索引 这里你需要知道DateFrame中布尔索引这个东西,可以用满足布尔条件的列值来过滤数据,如下 >>> df=pd.DataFrame(np.random.randn(4,4),columns=[A,B,C,D]) >>> df A B C D0 -0.018330 2.093506 -0.086293 -2.150479 1 0.104931 -0.271810 -0.054599 0.361612 2 0.590216 0.218049 0.157213 0.643540 3 -0.254449 -0.593278 -0.150455 - 0.244485 >>> df.A>0#布尔索引 0 False 1 True 2 True 3 False Name: A, dtype: bool #布尔索引应用 >>> df[df.A>0] A B C D 1 0.104931 -0.271810 -0.054599 0.361612 2 0.590216 0.218049 0.157213 0.643540 >>> isin() 添加一列E >>> df[E]=[a,a,c,b
经验分享 程序员 微信小程序 职场和发展