def remove_linear_drift(data): x = np.arange(len(data)) return data - stats.linregress(x, data).slope * x