标签:数据 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
(x, q, labels=None, retbins=False, precision=3, duplicates=‘raise‘)
>>>x 要进行分组的数据,数据类型为一维数组,或Series对象
>>>q 组数,即要将数据分成几组,后边举例说明
>>>labels 可以理解为组标签,这里注意标签个数要和组数相等
>>>retbins 默认为False,当为False时,返回值是Categorical类型(具有value_counts()方法),为True是返回值是元组
标签:数据 lse cto 相等 false label and 注意 bin
原文地址:https://www.cnblogs.com/fujian-code/p/9263449.html