Set maximum value (upper bound) in pandas DataFrame

后端 未结 3 1613
温柔的废话
温柔的废话 2020-12-02 01:50

I\'m trying to set a maximum value of a pandas DataFrame column. For example:

my_dict = {\'a\':[10,12,15,17,19,20]}
df = pd.DataFrame(my_dict)

df[\'a\'].se         


        
3条回答
  •  广开言路
    2020-12-02 02:23

    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)
    

提交回复
热议问题