[英]error using boolean indexing with pandas
I have a column "APNT_NA_ACTN"
that provides the type of coding used to hire employees: 我有一个
"APNT_NA_ACTN"
列,提供用于雇用员工的编码类型:
115, 515, 100, 786, 101, etc...
I have aliased my set of data as names, therefore names[:3]
provides three rows of the entire set. 我将我的数据集别名为名称,因此
names[:3]
提供整个集合的三行。
I have the ability to filter one type of code: 我有能力过滤一种代码:
names[names['APNT_NA_ACTN'] == 115]
names
but, I want to filter only: 115 and 515 from this column. 但是,我想仅过滤此列中的115和515。 I've tried the following
我尝试了以下内容
temp = names[(names['APNT_NA_ACTN'] == 115) & (names['APNT_NA_ACTN'] == 515)]
temp
and I have also tried: 我也尝试过:
temp = names.query('[100,515] in 'APNT_NA_ACTN')
can anyone offer assistance? 谁能提供帮助?
thanks 谢谢
so in all both suggestions below worked for me: 所以下面的所有建议都适合我:
1) temp = names[names['APNT_NA_ACTN'].isin([115,515])] 1)temp = names [names ['APNT_NA_ACTN']。isin([115,515])]
2) hiring_code = names['APNT_NA_ACTN'] temp = names[(hiring_code == 115) | 2)hiring_code = names ['APNT_NA_ACTN'] temp = names [(hiring_code == 115)| (hiring_code == 515)] temp[['NM_EMP_LST','NAT_ACTN_2_3','ACTN_YMD','ORG_LEV2','ORG_LEV3','APNT_NA_ACTN','APNT_YMD','SCD_LV_YMD','SSNO','year']]
(hiring_code == 515)] temp [['NM_EMP_LST','NAT_ACTN_2_3','ACTN_YMD','ORG_LEV2','ORG_LEV3','APNT_NA_ACTN','APNT_YMD','SCD_LV_YMD','SSNO','year'] ]
Use |
使用
|
(logical-or) instead of &
(logical-and): (逻辑 - 或)而不是
&
(逻辑 - 和):
hiring_code = names['APNT_NA_ACTN']
temp = names[(hiring_code == 115) | (hiring_code == 515)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.