0

I have a data frame similar to the one below:

    A
0   4.716
1   9.982
2   8.047
3   10.11
4   7.693

What I need to do is bin these values and store it in another column on this condition:

1) If value is less than 7 then '< 7'

2) If value from 7 to 7.5 then '7 - 7.5'

3) If value from 7.51 to 8 then '7.5 - 8.0'

4) If value from 8.01 to 8.5 then '8.0 - 8.5'

... continues ...

Finally, If value from 10.01 to 10.5 then '10.0 - 10.5'

using pd.cut here is not providing the results I need, the bins aren't of equal spread(equal spread as in for example: the values are binned from 6.92 - 7.116 where I would want this is two separate bins).

And since the data is large, running a loop is too time consuming. It would really be helpful if this can be solved? Thanks for any help.

Output required:

        A    B
0   4.716    < 7
1   9.982    9.5 - 10
2   8.047    8 - 8.5
3   10.11    10 - 10.5
4   7.693    7.5 -8

0 Answers0