Skip to main contentSkip to solution

Which of the following syntax is used to transpose a DataFrame?

Solution

✅ Correct Option: 2

In pandas, DataFrame.T is the attribute that returns the transpose of a DataFrame, swapping its rows and columns. For example, df.T gives the transposed DataFrame.


Option 1: the transpose method exists, but it must be called as DataFrame.transpose() with parentheses. Without them, it is only a reference to the method and does not transpose anything.

Keyboard Shortcuts

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