cut qcut

Posted fujian-code

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cut qcut相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

区别|Pandas-qcut( )与cut( )的区别

有没有办法在 sklearn 管道中链接 pd.cut FunctionTransformer?

非常简短的片段:PHP word cut

Final Cut Pro X中的音视频片段如何自由拖动?

熊猫 groupby 和 qcut

pandas的qcut()方法