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

Python pandas, filter our data with isin and other conditions

I have tried to use below codes to filter out records from a dataframe, for data is either with item codes 04901 or 04940 and Year is in 2022 however, this is not work property, it only return nil data, not sure why this is not work as intended, this only return no record

df.loc[(df[‘Item Code’].isin([‘04901’, ‘04940’])) & (df[‘Year’] == ‘2022’)]

If anybody can get me a hit ?

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

>Solution :

If years are integers use 2022 instead '2022':

df[(df['Item Code'].isin(['04901', '04940'])) & (df['Year'] == 2022)]

Or:

df[df['Item Code'].isin(['04901', '04940']) & df['Year'].eq(2022)]
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