1

I have a column "APNT_NA_ACTN" that provides the type of coding used to hire employees:

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.

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. 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])]

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']]

4
  • An alternative is names['APNT_NA_ACTN'].isin([115,515)] Commented Sep 11, 2014 at 13:16
  • I like this concept, however I receive the error: isin() takes exactly 2 arguments (3 given) I entered the code like this: names['APNT_NA_ACTN'].isin([115,515)] names Commented Sep 11, 2014 at 15:33
  • Sorry typo error, try this: names['APNT_NA_ACTN'].isin([115,515])] Commented Sep 11, 2014 at 15:35
  • yes, this totally worked... Commented Sep 11, 2014 at 15:43

2 Answers 2

2

An alternative is to use isin:

names['APNT_NA_ACTN'].isin([115,515])]

You can pass a list or a Series to the method

Sign up to request clarification or add additional context in comments.

Comments

1

Use | (logical-or) instead of & (logical-and):

hiring_code = names['APNT_NA_ACTN']
temp = names[(hiring_code == 115) | (hiring_code == 515)]

1 Comment

this seemed to provide what I needed. totally grateful all input!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.