I am looking for a clean way to reorder indexes in a group.
Code example:
import numpy as np import pandas as pd mydates = pd.date_range('1/1/2012', periods=1000, freq='D') myts = pd.Series(np.random.randn(len(mydates)), index=mydates) grouped = myts.groupby(lambda x: x.timetuple()[7]) mymin = grouped.min() mymax = grouped.max()
The above gives me what I want, the aggregate statistics on the Julian day of the year, but I would like to change the order of the group, so the last half (183 days) is placed before the first half. Using a regular numpy array:
myindex = np.arange(1,367) myindex = np.concatenate((myindex[183:],myindex[:183]))
But I can not do this with groupby, as it causes an implementation error.
Note. This is a cross-entry from google-groups . I also read on comp.lang.python, unfortunately, people tend to ignore some posts, for example. from google groups.
Thanks in advance,
Bevan
source share