文件说:
http://pandas.pydata.org/pandas-docs/dev/basics.html
"连续值可以使用切割(基于值的箱子)和qcut(基于样本分位数的箱子)功能"离散化"
听起来很抽象......我可以看到下面例子中的差异,但qcut(样本分位数)实际上是什么/意味着什么?你什么时候使用qcut与cut?
谢谢.
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]] …Run Code Online (Sandbox Code Playgroud)