Skip to main contentSkip to solution

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question