Which of the following statement is correct to display the first 3 rows of a DataFrame 'df'?
Which of the following statement is correct to display the first 3 rows of a DataFrame 'df'?
Solution
✅ Correct Option: 2
In pandas, df.head(n) returns the first n rows of a DataFrame, so df.head(3) displays the first 3 rows.
Option 1: df.tail(3) returns the last 3 rows, not the first.
Option 3: show() belongs to PySpark DataFrames, not pandas.
Option 4: pandas has no display() method on a DataFrame.
If no number is given, df.head() and df.tail() return 5 rows by default.
Related questions:
2025: 30 May Shift 2
2025: 15 May Shift 2
2026: 18 May Shift 2