I have a Dataframe named df which looks like -
pageno entity code rawentity
17727425 SAUDI CBCNTRY saudi
17727425 GARRA DRWRNAME garra
17727425 PO BOX RBCNTRY po box
17727425 NEW ZEALAND DRWRCNTRY new zealand
I also have a country list containing names of countries.It is of type 'list'.
I'm trying to keep only those value whose code is either - CBCNTRY or RBCNTRY or DRWRCNTRY and the entity should be in the countrylist.
The code that I have written is -
for row in df.itertuples():
if(row.code in ['DRWRCNTRY', 'RBCNTRY', 'CBCNTRY']):
if(row.entity not in countrylist):
df.drop((row.index), inplace=True)
But I'm getting the following error -
Error is: labels [<built-in method index of Pandas object at 0x0000020A1BCE4EB8>] not contained in axis
I just want to know why my approach is wrong and is there any thing better I can do apart from this method.
I have searched this error but I'm unable to get a satisfactory answer.