Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are pandas categories/bins written with an opening parenthesis but a closing bracket?

I came across the following on the pandas doc page for pd.cut():

Discretize into three equal-sized bins.

>>> pd.cut(np.array([1, 7, 5, 4, 6, 3]), 3)
... 
[(0.994, 3.0], (5.0, 7.0], (3.0, 5.0], (3.0, 5.0], (5.0, 7.0], ...
Categories (3, interval[float64]): [(0.994, 3.0] < (3.0, 5.0] ...

Why are the returned categories opened with a parenthesis ( but closed by a bracket ]? Does this denominate a special object in Python? At first I thought it was a typo but my console gives the same result.

like image 726
jorijnsmit Avatar asked Sep 05 '25 03:09

jorijnsmit


1 Answers

Because they denote intervals, wherein interval notation dictates that:

  • a square bracket is inclusive;
  • a parentheses is exclusive.

If a is your result, you'll see that a.categories gives you a Pandas IntervalIndex.

like image 103
Brad Solomon Avatar answered Sep 07 '25 15:09

Brad Solomon