0

enter image description here

a = [21,34,56,57,24,14,47,68]   

bins = np.arange(14, 68 + 5.4, 5.4)

pd.value_counts(pd.cut(a, bins, include_lowest=True),sort=False) 

The number 68 is ignored by the value_counts function. You can see that the number of occurrences of the number in the interval (62.6, 68) is 0.

2
  • And what's the bug and where? Commented Oct 31, 2020 at 11:26
  • The number 68 is ignored by the value_counts function. You can see that the number of occurrences of the number in the interval (62.6, 68) is 0 Commented Nov 1, 2020 at 10:37

1 Answer 1

1

Classic floating point arithmetic.

b = 14 + 10*5.4

c = 14+5.4+5.4+5.4+5.4+5.4+5.4+5.4+5.4+5.4+5.4 #10 increments

b==c
Out[195]: False

b-c
Out[196]: 1.4210854715202004e-14

b.as_integer_ratio()
Out[206]: (68, 1)

c.as_integer_ratio()
Out[207]: (4785074604081151, 70368744177664)

As your interval also starts just shy of 14, the exact integer ratio representation might be different, but the issue will still originate from the fact that the end of the final interval is up to floating point precision smaller than 68, thus not including 68 in its bin.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.