Utilizing Particular Criteria with DataFrame.loc in Pandas Python

Feedback

Question:

I possess an MSDT_A1 and my aim is to cherry-pick only those rows that have the ‘code’ available in my set. At present, I am attempting the following method:

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]

I encounter
typeerror: ‘series’ objects are mutable, thus they cannot be hashed
on the second one and
keyerror: false
on the first one.

What is the procedure to obtain information on the desired codes?


Solution:

Attempt to locate the value of dgdp based on the corresponding country code in the column labeled ”
Code’].isin
(country_codes)”.

Frequently Asked Questions