Home > Software design >  'method' object is not subscriptable - Pandas
'method' object is not subscriptable - Pandas

Time:02-14

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

CodePudding user response:

That is because isin() is a function 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., a[1], a[2] ...)

CodePudding user response:

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

  • Related