TypeError error while using isin function to filter rows in Pandas


TypeError error while using isin function to filter rows in Pandas



I met a TypeError error while using isin function to filter rows of my dataset in Pandas


df[~df['id'].isin('134399', '187013')]



The results:


df[~df['id'].isin('134399', '187013')]
Traceback (most recent call last):

File "<ipython-input-91-ba70cce02a1c>", line 1, in <module>
df[~df['id'].isin('134399', '187013')]

TypeError: isin() takes 2 positional arguments but 3 were given



Does someone know how to deal with this issue and can help me? Thanks.




1 Answer
1



You need to pass a single argument to isin (the extra one that's being counted in the 2 or 3 is self). You're passing two. That is, your argument should be a list containing the values you want to test against.


isin


self


df[~df['id'].isin(['134399', '187013'])]





My mistake, thanks. BTW, apostrophe on id is not very necessary, right?
– ahbon
Jul 2 at 3:23






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

JMeter fails on beanshell imports

Why in node-red my HTTP POST no receive payload from inject?

PHP contact form sending but not receiving emails