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

Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58

2 Answers2

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

Park
  • 2,446
  • 1
  • 16
  • 25
  • https://meta.stackoverflow.com/questions/366135/should-you-answer-questions-where-the-cause-of-the-problem-is-a-typo – jezrael Feb 14 '22 at 06:10
  • 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 – Mithilesh Tiwari Feb 14 '22 at 14:10
  • @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 https://stackoverflow.com/a/43216241/1779532 – Park Feb 14 '22 at 14:18
0

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

Shah Zain
  • 388
  • 4
  • 10