Set maximum value (upper bound) in pandas DataFrame

You can use clip.

Apply to all columns of the data frame:

df.clip(upper=15)

Otherwise apply to selected columns as seen here:

df.clip(upper=pd.Series({'a': 15}), axis=1)

Leave a Comment