Pandas how to use pd.cut()

后端 未结 5 497
时光取名叫无心
时光取名叫无心 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:06

    pd.cut documentation
    Include parameter right=False

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

提交回复
热议问题