Skip to content
Justice Tech School

Clip, Round and Cut Values

clip limits values to a range and round rounds. cut sorts numbers into labeled bins.

Example
import pandas as pd
import numpy as np
s = pd.Series([5, 17, 42, 99])
print(s.clip(10, 50).tolist())
print(pd.Series([1.234, 5.678]).round(1).tolist())
print(pd.cut(s, [0, 18, 65, 200], labels=['child', 'adult', 'senior']).tolist())

Result

[10, 17, 42, 50]
[1.2, 5.7]
['child', 'child', 'adult', 'senior']

Exercise

Limit to 0..10.

s.(0, 10)

Quiz Test

What does pd.cut do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.