After inspecting your dataset, the next practical skill is knowing how to select and filter the exact data you need. Real-world datasets can have hundreds of columns and thousands of rows, you rarely need all of it at once.
Pandas provides two powerful indexing methods, .loc[] and .iloc[], that allow you to precisely select rows, columns, or specific cells from a DataFrame.
Understanding the difference between these two and knowing when to use each one is a fundamental skill for any data analyst.
Setting Up — Sample DataFrame

Output
Selecting Columns — Basic SelectionBefore jumping into .loc[] and .iloc[], it's important to know how to select columns directly — the simplest form of data selection in Pandas.
.png)
Output of multiple column selection

.loc[] selects data using row labels (index) and column names. The syntax is straightforward, you provide the row label(s) first, then the column name(s). It is inclusive on both ends, meaning the stop label is included in the result.







.iloc[] selects data using integer positions (0-based index), similar to how you index Python lists. Unlike .loc[], it follows standard Python slicing rules where the stop position is excluded.


.png)






Beyond selecting by labels or positions, you often need to filter rows based on conditions — for example, selecting only employees in the Finance department or those earning above a certain salary.
This is done by passing a boolean condition inside df[] or combining it with .loc[].=
Single Condition


Use & for AND, | for OR, and wrap each condition in parentheses.

Combining conditions with .loc[] lets you filter rows and select specific columns at the same time, which is more efficient and cleaner.


When you want to match against multiple values in a column, .isin() is cleaner than chaining multiple OR conditions.
.png)
We have a sales campaign on our promoted courses and products. You can purchase 1 products at a discounted price up to 15% discount.