The qcut
behaves like this because it's more accurate. Here is an example:
for the ith level, it starts at quantile (i-1)*10%:
import pandas as pd
import numpy as np
a = np.random.rand(26*10+3)
r = pd.qcut(a, 10)
np.bincount(r.labels)
the output is:
array([27, 26, 26, 26, 27, 26, 26, 26, 26, 27])
If you want NTILE, you can calculate the quantiles yourself:
n = len(a)
ngroup = 10
counts = np.ones(ngroup, int)*(n//ngroup)
counts[:n%ngroup] += 1
q = np.r_[0, np.cumsum(counts / float(n))]
q[-1] = 1.0
r2 = pd.qcut(a, q)
np.bincount(r2.labels)
the output is:
array([27, 27, 27, 26, 26, 26, 26, 26, 26, 26])