pandas.cut(x,bins,right = True,labels = None,retbins = False,precision = 3,include_lowest = False)
主要功能:將x數組離散化成bins個分組。
參數詳解:
1、x
將要操作的數組對象。
1、bins
將要對x數組中的每個元素歸到bins個組中(間距不一定相等)
2、right
形式:right = True
含義:分組時是否包含右邊的值(即區間右邊是否是閉合)
3、labels
含義:是否用標簽來代替分組的結果。 示例如下:
4、precision
含義:精度
5、include_lowest
含義:是否包含左端點。
cut函數與groupby函數配合使用
cut函數返回的categorical對象可以直接傳遞給groupby,示例如下: