pandas value_count function bin order change

369 Views Asked by At

I am using value_count and bin to get one view our my database.

bin = np.concatenate((np.arange(0,10,1),np.arange(10,100,10),np.arange(100,1000,100)))
array([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  20,  30,
    40,  50,  60,  70,  80,  90, 100, 200, 300, 400, 500, 600, 700,
   800, 900])

My sample data is following:

summary_data['STOP_mean']
536826    4.100000
536827    1.500000
536828    2.000000
Name: STOP_mean, Length: 536829, dtype: float64

However, bin provide result as following:

which is not same order as pandas result.

summary_data['STOP_mean'].value_counts(bins = bin)


(-0.001, 1.0]     172259
(1.0, 2.0]        163468
(2.0, 3.0]         57479
(10.0, 20.0]       30479
(3.0, 4.0]         29108
(4.0, 5.0]         18480

why (10.0,20.0] pop right after (2.0.3.0]

Already tried reset_index and sort_index does not work. (Looks like it is interval index. How to reset that one?)

sort_index result:

<bound method Series.sort_index of (-0.001, 1.0]     172259
(1.0, 2.0]        163468
(2.0, 3.0]         57479
(10.0, 20.0]       30479
(3.0, 4.0]         29108
(4.0, 5.0]         18480

Solved

sort_index(axis=0) solved problem

0

There are 0 best solutions below