cut()
noun
say it: “KUT” /ˈkʌt/
A pandas function that sorts numbers into named ranges, such as budget, mid and premium, using the edges you give it.
What does cut() do in pandas?
cut(), written pd.cut, sorts numbers into labeled bands, such as budget, mid and premium, from a list of edges you
choose. A value sitting exactly on an edge goes in the band below it, unless right=False puts it in the band above.
import pandas as pd
prices = pd.Series([25.0, 50.0, 140.0])
bands = pd.cut(prices, bins=[0, 50, 100, 1000], labels=["budget", "mid", "premium"], right=False)
print(bands.tolist()) # ['budget', 'mid', 'premium']
In a sentence
- “cut() put every product in a budget, mid or premium price band.”
- “With cut(), the ages became groups: under 18, 18 to 64, and 65 and over.”
Level: Journeyman · More Python terms at this level
Updated