These free B.Pharm notes on filtering and selecting data in pandas cover chapter 21 of Basics of Python Programming for Pharmaceutical Sciences (BP101T), a first-semester subject. Read the key points below, then study the complete chapter PDF. You can browse every chapter in the Basics of Python Programming for Pharmaceutical Sciences category.
Table of Contents
Read the following document for full information
Overview of filtering and selecting data in pandas
These notes show how to pull out the records and variables needed for an analysis after a dataset has been cleaned. They cover selecting single and multiple columns, selecting rows by label with loc[] and by position with iloc[], boolean indexing, combining conditions with & and |, filtering with .isin(), and filtering rows while selecting columns together using .loc[].
Key points on filtering and selecting data in pandas
- Selecting one column with square brackets returns a Pandas Series, while selecting a list of column names returns a smaller DataFrame.
- The loc[] indexer selects data using index or column labels, whereas iloc[] selects data according to its integer position.
- With loc[0:3] the ending label 3 is included, but with iloc[0:3] the ending position 3 is excluded, following normal Python slicing rules.
- In boolean indexing a condition on a column produces True and False values, and Pandas keeps only the rows where the condition is True.
- Conditions are combined with & for logical AND and | for logical OR, and each individual condition should be enclosed in parentheses.
Relevance to pharmacy practice
Pharmacists and researchers often need only certain patients, time points or adverse events from a larger dataset. Filtering lets them quickly isolate records such as ongoing reactions, probable drug-related events or concentrations above the mean for focused pharmacovigilance and pharmacokinetic analysis.
Every chapter in this subject builds on the one before it, so do not skip topics that look simple. Definitions, principles, procedures and examples are the parts that examiners return to most often, and a clear understanding here will also make later subjects easier to follow in the coming semesters.
Frequently asked questions on filtering and selecting data in pandas
What is the difference between loc and iloc in Pandas?
loc[] selects data using labels and includes the end label in a slice, while iloc[] selects by integer position and excludes the end position, like normal Python slicing.
How do you combine two conditions when filtering a DataFrame?
Use & when all conditions must be true and | when at least one must be true, and put each condition inside its own parentheses.
What does the isin() method do in Pandas?
isin() checks whether a column’s values fall within a given list, such as [“Probable”, “Possible”], so you can keep several categories without writing separate equality checks joined by OR.
Quick revision checklist
Use this self-test after reading the chapter on filtering and selecting data in pandas. If you can do all of the following without looking at your notes, you are ready for the exam.
- I can explain: how to select one or more columns
- I can explain: the difference between loc[] and iloc[]
- I can explain: how boolean indexing filters rows
- I can explain: how to combine conditions with & and |
- I can explain: when to use the isin() method
Study and exam tips
Start by reading the chapter once for the overall idea, then revise filtering and selecting data in pandas using headings, definitions, principles, reactions and examples. Short-answer questions in the university exam usually ask for definitions, principles, procedures, reactions and uses, so write these in your own words and practise the equations, tables and flow charts that the chapter has.
For wider reading, standard books and open resources such as the NCBI Bookshelf help you confirm terms and see more examples. Revise filtering and selecting data in pandas again a day later and again a week later, because spaced revision improves long-term memory.
This page is part of the Basics of Python Programming for Pharmaceutical Sciences series for first-semester B.Pharm students on B.Pharm Guru, where every chapter has a short summary and a full PDF. Bookmark this page and share it with classmates who are preparing for the same exam.
Related notes: 23. INTRODUCTION TO MATPLOTLIB, 24. CREATING LINE PLOTS, HISTOGRAMS, SCATTER PLOTS, AND BOX PLOTS.
Next: 22. GROUPING DATA AND PERFORMING AGGREGATION FUNCTIONS. Back to the Basics of Python Programming for Pharmaceutical Sciences category.




