Pandas how to use pd.cut()

后端 未结 5 498
时光取名叫无心
时光取名叫无心 2020-12-02 17:28

Here is the snippet:

test = pd.DataFrame({\'days\': [0,31,45]})
test[\'range\'] = pd.cut(test.days, [0,30,60])

Output:

             


        
5条回答
  •  情书的邮戳
    2020-12-02 18:04

    A sample of how the .cut works

    s=pd.Series([168,180,174,190,170,185,179,181,175,169,182,177,180,171)
        pd.cut(s,3)
        #To add labels to bins
        pd.cut(s,3,labels=["Small","Medium","Large"])
    

    This can be used directly on a range

提交回复
热议问题