Nicolas741
Nicolas741

Reputation: 27

Pandas .qcut giving me unequal bin sizes

I have a stocks price returns pandas dataframe and I want to calculate the deciles for each date (which is the index). This is the code that I am using:

deciles = pd.qcut(stock_returns.rank(method = 'first'), 10, labels = False)

However, for each date the bins are uneven, like this example date slice:

0.0: 90
0.1: 69
0.2: 44
0.3: 43
0.4: 30
0.5: 23
0.6: 14
0.7: 20
0.8: 21
0.9: 24

I have also tried this code, but same happens:

deciles = pd.qcut(stock_returns, 10, labels = False)

Any help?

Upvotes: 0

Views: 531

Answers (1)

Tim Roberts
Tim Roberts

Reputation: 54743

pd.qcut does not tell you how many things are each bin. That wouldn't be very useful. What it returns to you is an array showing which bin the corresponding element would go in. If 90 was the first value returned, then the first element of stock_returns would go in bin #90.

Upvotes: 0

Related Questions