<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def downsample(self, sample_factor=2):
 """ Downsample series by an integer factor by averaging. Parameters sample_factor : positive integer, optional, default=2 Factor for downsampling. """

        if sample_factor < 0:
            raise Exception('Factor for subsampling must be postive, got %g' % sample_factor)
        newlength = floor(len(self.index) / sample_factor)
        func = lambda v: v[0:int(newlength * sample_factor)].reshape(-1, sample_factor).mean(axis=1)
        newindex = arange(newlength)
        return self.map(func, index=newindex)