热线电话:13121318867

登录
2018-12-11 阅读量: 778
布尔索引

# 使用单个列的值来选择数据

df[df.A>0]

A B C D

2013-01-01 0.615859 0.354072 0.741003 0.055112

2013-01-02 0.985261 0.017241 0.481214 0.538970

2013-01-03 0.104701 0.647015 0.812034 0.477090

2013-01-04 0.252073 0.862004 0.063743 0.900931

2013-01-05 0.079194 0.779128 0.907441 0.659853

2013-01-06 0.790942 0.906111 0.093382 0.032258

df[df['A']>0]

A B C D

2013-01-01 0.615859 0.354072 0.741003 0.055112

2013-01-02 0.985261 0.017241 0.481214 0.538970

2013-01-03 0.104701 0.647015 0.812034 0.477090

2013-01-04 0.252073 0.862004 0.063743 0.900931

2013-01-05 0.079194 0.779128 0.907441 0.659853

2013-01-06 0.790942 0.906111 0.093382 0.032258

# 满足布尔条件的DataFrame中选择值

df[df>0]

A B C D

2013-01-01 0.615859 0.354072 0.741003 0.055112

2013-01-02 0.985261 0.017241 0.481214 0.538970

2013-01-03 0.104701 0.647015 0.812034 0.477090

2013-01-04 0.252073 0.862004 0.063743 0.900931

2013-01-05 0.079194 0.779128 0.907441 0.659853

2013-01-06 0.790942 0.906111 0.093382 0.032258

# 使用isin过滤

df2=df.copy()

df2['E']=['one','one','two','three','four','three']

df2

A B C D E

2013-01-01 0.615859 0.354072 0.741003 0.055112 one

2013-01-02 0.985261 0.017241 0.481214 0.538970 one

2013-01-03 0.104701 0.647015 0.812034 0.477090 two

2013-01-04 0.252073 0.862004 0.063743 0.900931 three

2013-01-05 0.079194 0.779128 0.907441 0.659853 four

2013-01-06 0.790942 0.906111 0.093382 0.032258 three

df2[df2['E'].isin(['two','four'])]

A B C D E

2013-01-03 0.104701 0.647015 0.812034 0.477090 two

2013-01-05 0.079194 0.779128 0.907441 0.659853 four

0.0000
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子