Q.Which of the following command will not show first five rows from the Pandas series named S1 ? (A) S1[0:5] (B) S1.head() (C) S1.head(5) (D) S1.head[0:5]
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Option (D) S1.head[0:5] is the only command that will not show the first five rows, because it uses square brackets instead of parentheses — a syntax error in Pandas.
Let’s think about what each of these commands actually does. In Pandas, a Series is like a labelled one-dimensional array. When you want to peek at the beginning of a Series, you have two standard ways: slicing with square brackets, or using the .head() method.
Option (A) S1[0:5] uses standard Python slicing. This works perfectly — it returns the elements at index positions 0, 1, 2, 3, and 4, which are the first five rows. Slicing in Pandas follows the same rules as Python lists: start inclusive, end exclusive.
Option (B) S1.head() calls the .head() method with no argument. By default, .head() returns the first five rows. So this is correct and will show exactly what we want.
Option (C) S1.head(5) is the explicit version of the same method — you’re telling Pandas “give me the first 5 rows.” This works identically to S1.head().
Now look at option (D) S1.head[0:5]. This is the odd one out. The .head() is a method, which means it must be called with parentheses — like .head() or .head(5). Using square brackets after .head tries to treat it as if it were a list or a dictionary, not a method. Python will raise a TypeError saying that the object is not subscriptable. This command will not execute at all, let alone show the first five rows. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.