码迷,mamicode.com
首页 > 其他好文 > 详细

cut qcut

时间:2018-07-04 16:04:02      阅读:482      评论:0      收藏:0      [点我收藏+]

标签:数据   lse   cto   相等   false   label   and   注意   bin   

factors = np.random.randn(30)

In [11]:
pd.cut(factors, 5)
Out[11]:
[(-0.411, 0.575], (-0.411, 0.575], (-0.411, 0.575], (-0.411, 0.575], (0.575, 1.561], ..., (-0.411, 0.575], (-1.397, -0.411], (0.575, 1.561], (-2.388, -1.397], (-0.411, 0.575]]
Length: 30
Categories (5, object): [(-2.388, -1.397] < (-1.397, -0.411] < (-0.411, 0.575] < (0.575, 1.561] < (1.561, 2.547]]

In [14]:
pd.qcut(factors, 5)
Out[14]:
[(-0.348, 0.0899], (-0.348, 0.0899], (0.0899, 1.19], (0.0899, 1.19], (0.0899, 1.19], ..., (0.0899, 1.19], (-1.137, -0.348], (1.19, 2.547], [-2.383, -1.137], (-0.348, 0.0899]]
Length: 30
Categories (5, object): [[-2.383, -1.137] < (-1.137, -0.348] < (-0.348, 0.0899] < (0.0899, 1.19] < (1.19, 2.547]]`

cut是等距,qcut是等频

qcut方法,参考链接:http://pandas.pydata.org/pandas-docs/stable/generated/pandas.qcut.html

  1).参数:pandas.qcut(xqlabels=Noneretbins=Falseprecision=3duplicates=‘raise‘)

    >>>x 要进行分组的数据,数据类型为一维数组,或Series对象

    >>>q 组数,即要将数据分成几组,后边举例说明

    >>>labels 可以理解为组标签,这里注意标签个数要和组数相等

    >>>retbins 默认为False,当为False时,返回值是Categorical类型(具有value_counts()方法),为True是返回值是元组

 

 

 

cut qcut

标签:数据   lse   cto   相等   false   label   and   注意   bin   

原文地址:https://www.cnblogs.com/fujian-code/p/9263449.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!