Skip to main contentSkip to solution

Which of the following command for a given dataframe 'ResultDF' will set all values in 'ResultDF' to 0?

Solution

✅ Correct Option: 3

ResultDF[:] = 0 selects every row of the DataFrame using the slice [:] and assigns 0 to all of them. The DataFrame keeps its shape, index and column names, and every value becomes 0.


Option 1: this only rebinds the name ResultDF to the integer 0. The DataFrame is no longer referenced, and it is not filled with zeros.

Option 4: == is a comparison, not an assignment. It returns a DataFrame of True/False values and leaves ResultDF unchanged.

Option 2: ResultDF.0 is invalid syntax, since an attribute name cannot be a number.

Keyboard Shortcuts

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