It feels so straight forward but I haven't found the answer to my question yet. How does one group by proximity, or closeness, of two floats in pandas?
Ok, I could do this the loopy way but my data is big and I hope I can expand my pandas skills with your help and do this elegantly:
I have a column of times in nanoseconds in my DataFrame. I want to group these based on the proximity of their values to little clusters. Most of them will be two rows per cluster maybe up to five or six. I do not know the number of clusters. It will be a massive amount of very small clusters. I thought I could e.g. introduce a second index or just an additional column with 1 for all rows of the first cluster, 2 for the second and so forth so that groupby gets straight forward thereafter. something like:
| t (ns) | cluster | |
|---|---|---|
| 71 | 1524957248.4375 | 1 |
| 72 | 1524957265.625 | 1 |
| 699 | 14624846476.5625 | 2 |
| 700 | 14624846653.125 | 2 |
| 701 | 14624846661.287 | 2 |
| 1161 | 25172864926.5625 | 3 |
| 1160 | 25172864935.9375 | 3 |
Thanks for your help!