<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def detrend(self, method='linear', order=5):
 """ Detrend series data with linear or nonlinear detrending. Preserve intercept so that subsequent operations can adjust the baseline. Parameters method : str, optional, default = 'linear' Detrending method order : int, optional, default = 5 Order of polynomial, for non-linear detrending only """

        check_options(method, ['linear', 'nonlinear'])

        if method == 'linear':
            order = 1

        def func(y):
            x = arange(len(y))
            p = polyfit(x, y, order)
            p[-1] = 0
            yy = polyval(p, x)
            return y - yy

        return self.map(func)