The Cut and Qcut Functions

Learn how to use the cut and qcut Pandas functions.

The cut function

Both the cut and qcut functions convert columns with continuous values to categorical columns, but they apply different techniques. The cut function divides the entire value range into intervals of the same size, called bins. The range covered by each bin will be the same. If the minimum value is 0 and the maximum value is 10 and we want to divide the values into four groups (bins). The bins will be created as follows:

  • (-0.01, 2.5]
  • (2.5, 5]
  • (5, 7.5]
  • (7.5, 10]

The lower bounds aren’t inclusive. Thus, the lower bound of the smallest bin is slightly less than the smallest value to include it. Let’s look at an example to demonstrate how the cut function works in code.

Get hands-on with 1200+ tech skills courses.