Skip to main contentSkip to solution

Which function is used to calcuate quartile in pandas DataFrame 'df'?

Solution

✅ Correct Option: 4

df.quantile() returns the value at a given quantile of each column. Its parameter q takes a value between 0 and 1, so quartiles are q=0.25q = 0.25, 0.50.5 and 0.750.75 (Q1, Q2 and Q3). For example, df.quantile([0.25, 0.5, 0.75]) returns all three quartiles. The default is q=0.5, the median.


Option 1: pandas has no quartile() method. Quartiles are found with quantile().

Option 2: quarter is a datetime attribute (for example dt.quarter) that gives the calendar quarter of a date, not a statistical quartile.

Option 3: aggregate() applies a function such as sum or mean. It does not compute quartiles by itself.

Keyboard Shortcuts

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