Skip to content

Commit db6d369

Browse files
committed
ENH: shell of quantile cut function qcut, #1378
1 parent c14c094 commit db6d369

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

pandas/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636
from pandas.tools.merge import merge, concat, ordered_merge
3737
from pandas.tools.pivot import pivot_table, crosstab
3838
from pandas.tools.plotting import scatter_matrix
39-
from pandas.tools.tile import cut
39+
from pandas.tools.tile import cut, qcut

pandas/tools/tile.py

+32
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def cut(x, bins, right=True, labels=None, retbins=False, precision=3):
4747
a categorical variable. For example, `cut` could convert ages to groups
4848
of age ranges.
4949
50+
Any NA values will be NA in the result
51+
5052
Examples
5153
--------
5254
>>> cut(np.array([.2, 1.4, 2.5, 6.2, 9.7, 2.1]), 3, retbins=True)
@@ -128,6 +130,36 @@ def cut(x, bins, right=True, labels=None, retbins=False, precision=3):
128130

129131
return labels, bins
130132

133+
134+
def qcut(x, n, ties_method='average'):
135+
"""
136+
Quantile-based discretization function. Discretize variable into
137+
equal-sized buckets based on rank. For example 1000 values for 10 quantiles
138+
would produce 1000 integers from 0 to 9 indicating the
139+
140+
Parameters
141+
----------
142+
x : ndarray or Series
143+
n : integer
144+
Number of quantiles. 10 for deciles, 4 for quartiles, etc.
145+
ties_method : {'average', 'min', 'max', 'first'}, default 'average'
146+
average: average rank of group
147+
min: lowest rank in group
148+
max: highest rank in group
149+
first: ranks assigned in order they appear in the array
150+
151+
Returns
152+
-------
153+
154+
Notes
155+
-----
156+
157+
Examples
158+
--------
159+
"""
160+
pass
161+
162+
131163
def _format_label(x, precision=3):
132164
fmt_str = '%%.%dg' % precision
133165
if com.is_float(x):

0 commit comments

Comments
 (0)