question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

qcut() should make sure the bins bounderies are unique before passing them to _bins_to_cuts

See original GitHub issue

xref #8309

for example:

pd.qcut([1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5], [0.00001, 0.5])

will raise “ValueError: Bin edges must be unique: array([ 1., 1.])” exception

Fix suggestion - add one new line:

def qcut(x, q, labels=None, retbins=False, precision=3):
    if com.is_integer(q):
        quantiles = np.linspace(0, 1, q + 1)
    else:
        quantiles = q
    bins = algos.quantile(x, quantiles)
--->bins = np.unique(bins)
    return _bins_to_cuts(x, bins, labels=labels, retbins=retbins,
        precision=precision, include_lowest=True)

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

8reactions
dukebodycommented, May 13, 2015

I think we could add a “duplicate_edges” parameter, with the following options:

Does it look reasonable? What do you think?

2reactions
rainjacketcommented, Nov 30, 2015

dukebody’s suggestion looks good to me.

For my use case, I would prefer for qcut to just return the (non-unique) bin list, and let me handle it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to qcut with non unique bin edges? - Stack Overflow
The problem is that pandas.qcut chooses the bins/quantiles so that each one has the same number of records, but all records with the...
Read more >
Binning Data with Pandas qcut and cut
Pandas qcut and cut are both used to bin continuous values into discrete buckets or bins. This article explains the differences between the ......
Read more >
All Pandas qcut() you should know for binning numerical data ...
Pandas has 2 built-in functions cut() and qcut() for transforming numerical data into categorical data. cut() bins data into discrete intervals ...
Read more >
Pandas cut And qcut Method For Data Binning - Regenerative
Another method for binning. But the concept is different. In qcut, when you pass q=4, it will try to divide the population equally...
Read more >
pandas.qcut — pandas 1.5.2 documentation
Bins are represented as categories when categorical data is returned. binsndarray of floats. Returned only if retbins is True. Notes. Out of bounds...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found