1

I have the following two lines of codes

temp['AD_Free_Cancel'] = temp[(temp['ISFREEPOLICY']=='N') & (temp['PRODUCT'].isin['SAD1','SAD2','SAD3','SAD4','SADFR1','SADFR2','SIAD']) & (temp['POLICYSTATUS']=='C')]

temp['AD_Paid_Cancel'] = temp[(temp['ISFREEPOLICY']!='N') & (temp['PRODUCT'].isin['SAD1','SAD2','SAD3','SAD4','SADFR1','SADFR2','SIAD']) & (temp['POLICYSTATUS']=='C')]

Can someone please help me understand the error and how can I fix it? Thank You

2
  • 1
    missing ( in .isin([ Commented Feb 14, 2022 at 6:05
  • typo, so closing Commented Feb 14, 2022 at 6:05

2 Answers 2

2

That is because isin() is a function for Series but you are using it like .isin[] ..., You can replace it as isin(...), as follows:

temp['AD_Free_Cancel'] = temp[(temp['ISFREEPOLICY']=='N') & (temp['PRODUCT'].isin('SAD1','SAD2','SAD3','SAD4','SADFR1','SADFR2','SIAD')) & (temp['POLICYSTATUS']=='C')]

temp['AD_Paid_Cancel'] = temp[(temp['ISFREEPOLICY']!='N') & (temp['PRODUCT'].isin('SAD1','SAD2','SAD3','SAD4','SADFR1','SADFR2','SIAD')) & (temp['POLICYSTATUS']=='C')]

If you use like isin[...], Python will think it is a kind of subscriptable variable such as a list (e.g., a1, a[2] ...)

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

3 Comments

I changed my code around isin function temp['AD_Free_Cancel'] = temp[(temp['ISFREEPOLICY']=='N') & (temp['PRODUCT'].isin(['SAD1','SAD2','SAD3','SAD4','SADFR1','SADFR2','SIAD'])) & (temp['POLICYSTATUS']=='C')] temp['AD_Paid_Cancel'] = temp[(temp['ISFREEPOLICY']!='N') & (temp['PRODUCT'].isin(['SAD1','SAD2','SAD3','SAD4','SADFR1','SADFR2','SIAD'])) & (temp['POLICYSTATUS']=='C')] but now getting error "Wrong number of items passed 12, placement implies 1" Please help
@MithileshTiwari It is really hard to guess why it happens without any backgound knowledge. As I guess, temp['AD_Free_Cancel'] is a Series but it seems that you are trying to assign Dataframe with 12 columns into a Series, which has 1 column. That is logically wrong. See stackoverflow.com/a/43216241/1779532
0

You are having error because isin() is a function but you are using it as .isin[], It should be isin()

Comments

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.