Question:

Briefly explain the purpose of Boolean Indexing with respect to DataFrames. Support your answer with a suitable example.

Show Hint

Boolean indexing selects only those rows of a DataFrame for which a condition is True. Give a short example such as df[df['Marks'] > 80].
Updated On: Oct 20, 2026
Show Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Define Boolean Indexing:
Boolean indexing means selecting rows of a DataFrame using a condition that gives True or False for each row.
Only the rows where the condition is True are kept.

Step 2: State the purpose:
It helps us filter data quickly without a loop. For example, we can pick all students with marks above 80 in one line.

Step 3: Show the working with an example:
Take this DataFrame.
import pandas as pd
df = pd.DataFrame({'Name': ['Asha', 'Ravi', 'Meena'], 'Marks': [92, 75, 85]})
print(df[df['Marks'] > 80])
The condition df['Marks'] > 80 gives the Boolean Series True, False, True.
Placing it inside df[ ] keeps only the rows with True.

Step 4: Write the output:
The rows for Asha (92) and Meena (85) are shown. The row for Ravi (75) is left out.

Final Answer:
Boolean indexing filters the rows of a DataFrame by a True/False condition. In the example, df[df['Marks'] > 80] returns the rows of Asha and Meena.
Was this answer helpful?
0
0