This question describes exactly what I want to do and this answer works perfectly on my example data. However, at some point I run into a problem when working with my real, much larger dataset. In my real dataset, I would like to subsample to every hundredth point. Currently, the index goes like 259.05, 259.06, 259.07, 259.08, 259.09, 259.1, 259.11, 259.12, 259.13, 259.14... and I would like to subsample it just to 259, 260, 261... But I would like to start at some reasonable numbers, such as 260 or at least 259.5.
However, when I get to the point as suggested in the abovementioned answer, the following code works:
s = (df.index.to_series()).astype(int)
df.groupby(s).mean().set_index(s.index[13::100])
producing 259.18, 260.18, 261.18 .... But If I start at any higher point,
df.groupby(s).mean().set_index(s.index[14::100])
I get: ValueError: Length mismatch: Expected axis has 635 elements, new values have 634 elements
Long story short: Input:
index some data
259.05 x
259.06 x
259.07 x
259.08 x
259.09 x
259.1 x
259.11 x
259.12 x
259.13 x
259.14 x
259.15 x
… …
Desired output:
index some data
260 mean x
261 mean x
262 mean x
263 mean x
264 mean x
265 mean x
266 mean x
267 mean x
268 mean x
269 mean x
270 mean x
… …
Apparently this is because the length of the data is not sufficient for another full 100. So how can I achieve having it sampled at the desired points?