How to split values into discrete intervals categories with Pandas in Python

1 min

Using the pandas.cut() method you can split the distribution into discrete intervals.

import pandas as pd

# We read a sample dataset from the web.
df = pd.read_csv(''\
 # We use the cut method to split into discrete intervals
 df["discrete_intervals"] = pd.cut(df["sepal_length"], 
# We set the canvas
fig, axes = plt.subplots(1, 1, figsize=(6,4))

# We plot the graph

# We tidy the layout

# We save the fig
How to bin values into discrete intervals

Here is the result

Here you are! You now know how to split values into discrete interval categories.