I have a script that produces bins using np.digitize of values like so:
| time | butter | bin |
| :---- | :------ | :--- |
| 2022-07-04 17:33:45+00:00 | 1.041967 | 3 |
| 2022-07-04 17:34:00+00:00 | 1.041967 | 4 |
| 2022-07-04 17:34:15+00:00 | 1.041966 | 4 |
| 2022-07-04 17:34:30+00:00 | 1.041967 | 4 |
| 2022-07-04 17:34:45+00:00 | 1.041968 | 4 |
| 2022-07-04 17:35:00+00:00 | 1.041969 | 4 |
| 2022-07-04 17:35:15+00:00 | 1.041971 | 4 |
| 2022-07-04 17:35:30+00:00 | 1.041973 | 4 |
| 2022-07-04 17:35:45+00:00 | 1.041975 | 4 |
| 2022-07-04 17:36:00+00:00 | 1.041977 | 5 |
| 2022-07-04 17:36:15+00:00 | 1.041979 | 5 |
| 2022-07-04 17:36:30+00:00 | 1.041981 | 5 |
| 2022-07-04 17:36:45+00:00 | 1.041983 | 5 |
| 2022-07-04 17:37:00+00:00 | 1.041985 | 5 |
| 2022-07-04 17:37:15+00:00 | 1.041986 | 6 |
| 2022-07-04 17:37:30+00:00 | 1.041987 | 6 |
| 2022-07-04 17:37:45+00:00 | 1.041988 | 6 |
| 2022-07-04 17:38:00+00:00 | 1.041989 | 6 |
bins can increase/decrease and they can skip bins.
How can I calculate the local min/max of each bin, so that the result looks like this:
| time | butter | bin | min | max |
| :---- | :------ | :--- | :--- | :--- |
| 2022-07-04 17:33:45+00:00 | 1.041967 | 3 | 1.041967 | 1.041967 |
| 2022-07-04 17:34:00+00:00 | 1.041968 | 4 | 1.041966 | 1.041975 |
| 2022-07-04 17:34:15+00:00 | 1.041966 | 4 | 1.041966 | 1.041975 |
| 2022-07-04 17:34:30+00:00 | 1.041967 | 4 | 1.041966 | 1.041975 |
| 2022-07-04 17:34:45+00:00 | 1.041968 | 4 | 1.041966 | 1.041975 |
| 2022-07-04 17:35:00+00:00 | 1.041969 | 4 | 1.041966 | 1.041975 |
| 2022-07-04 17:35:15+00:00 | 1.041971 | 4 | 1.041966 | 1.041975 |
| 2022-07-04 17:35:30+00:00 | 1.041973 | 4 | 1.041966 | 1.041975 |
| 2022-07-04 17:35:45+00:00 | 1.041975 | 4 | 1.041966 | 1.041975 |
| 2022-07-04 17:36:00+00:00 | 1.041977 | 5 | 1.041977 | 1.041985 |
| 2022-07-04 17:36:15+00:00 | 1.041979 | 5 | 1.041977 | 1.041985 |
| 2022-07-04 17:36:30+00:00 | 1.041981 | 5 | 1.041977 | 1.041985 |
| 2022-07-04 17:36:45+00:00 | 1.041983 | 5 | 1.041977 | 1.041985 |
| 2022-07-04 17:37:00+00:00 | 1.041985 | 5 | 1.041977 | 1.041985 |
| 2022-07-04 17:37:15+00:00 | 1.041986 | 6 | 1.041986 | 1.041989 |
| 2022-07-04 17:37:30+00:00 | 1.041987 | 6 | 1.041986 | 1.041989 |
| 2022-07-04 17:37:45+00:00 | 1.041988 | 6 | 1.041986 | 1.041989 |
| 2022-07-04 17:38:00+00:00 | 1.041989 | 6 | 1.041986 | 1.041989 |
I was trying something with np.where and np.diff with np.sign but I haven't figured it out nor do I feel that's the best way to go about the question.
thank you in advance.