Advertisement

pandas.cut用于对数据进行分组处理,请了解各参数的作用

阅读量:
复制代码
    # 导入模块
    import pandas as pd
    import numpy as np
    
    
    # 使用 cut 的默认参数
    # cut的作用:对数据进行分组处理。bins 默认是左开右闭。
    # 本例中,是将 x 中的数据,逐个归类到 bins-“(1, 4], (4, 6], (6, 10]” 中。
    pd.cut(x=np.array([1, 7, 5, 4, 6, 3]), bins=[1, 4, 6, 10])
    
    
      
      
      
      
      
      
      
      
      
    
在这里插入图片描述
复制代码
    """ 第1组:right 参数 """
    
    # 1) True:左开右闭,( , ]
    # 2) False:左闭右开,[ , )
    
    pd.cut(np.array([1, 7, 5, 4, 6, 3]), [1, 4, 6, 10], right=True)

全部评论 (0)

还没有任何评论哟~