VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-calculate-quantiles-by-group-in-pandas/

⇱ How to Calculate Quantiles by Group in Pandas? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Calculate Quantiles by Group in Pandas?

Last Updated : 23 Jul, 2025

In this article, how to calculate quantiles by group in Pandas using Python.

There are many methods to calculate the quantile, but pandas provide groupby.quantile() function to find it in a simple few lines of code. This is the Method to use when the desired quantile falls between two points.

Syntax: 

DataFrameGroupBy.quantile(self, q=0.5, interpolation='linear')

Parameters:  

  • q : float or array-like, default 0.5 (50% quantile) Values are given between 0 and 1 providing the quantiles to compute.
  • Interpolation : {‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}

In this method, the values and interpolation are passed as parameters. By default, the q value will be 0.5 and interpolation will be Linear. This returns the series or Dataframe determined by the GroupBy object.

Dataframe in use:

👁 Image
dataframe

Example 1: Calculate quantiles by group

Output:

👁 Image
output

Example 2: Calculate quantiles by group

Output:

👁 Image
output
Comment