Home > Back-end >  How to use specific conditions in dataFrame.loc in pandas python?
How to use specific conditions in dataFrame.loc in pandas python?

Time:01-21

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.

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

CodePudding user response:

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

  •  Tags:  
  • Related