Panda.qcut inside logic of binning
When using qcut(), it will sort the array, and create bin boundaries based on the values at positions data[(len(data)*index / bin].
In your case, a lot of those values are equal. You should have gotten a warning about that, unless you explicitly told it to "drop" duplicate values by calling pd.qcut(age, q=6, duplicates='drop').
For entropy-based binning, you need a class label. You get bins with boundaries based on age, such that the class in each bin is (ideally) as uniform as possible. In your example, we only have age, so we can't use entropy-based binning.
For your particular setting, I would use qcut(), set the number of bins high enough, tell it to drop duplicates, and see what bins come out of it. One of the bins will have a lot of data in it (the first one), but that can't be helped, since our data is so highly skewed.
I am experimenting with different methods of binning a continuous variable. two methods that I used - qcut and entropy_based_binning method bin_sequence. For testing I created a data with 100 values. I made the data skewed by putting value = 1 for first 50 records, 2 for next few records, 5, 12 for few records and then randomly few numbers.
When I tried to run it with number of bins = 6 it created only 3 bins with qcut method. from pandas documentation it is not clear how it behaves with skewed data. Also, there is very limited information available on entropy based binning. Would appreciate if someone can share details. Pros and cons of each method
age
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
12
12
12
12
12
12
12
12
12
5
5
5
5
5
5
5
5
20
20
20
20
20
20
20
25
26
27
93
50
54