Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use specific conditions in dataFrame.loc in pandas python?

I have a pandas Dataframe and i only want to select the rows if the ‘code’ is available in my set.
I am currently trying this:

country_codes = set(set(dle['Code']) & set(dgdp['Code']))
dgdp.loc[dgdp['Code'].str in country_codes]

or

dgdp.loc[dgdp['Code'] in country_codes]

On the second one I get the problem
TypeError: ‘Series’ objects are mutable, thus they cannot be hashed
and in the first one I get KeyError: False.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I get the info for the codes that I want?

>Solution :

try: dgdp.loc[dgdp[‘Code’].isin(country_codes)]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading