detrend removes a linear drift. savgol_filter smooths.
Goal
Detrend a ramp-plus-sine and print the mean.
from scipy import signal
x = np.linspace(0, 4, 80)
y = 3 * x + np.sin(2 * np.pi * x)
d = signal.detrend(y)
print(round(float(np.mean(d)), 6))from scipy.signal import savgol_filter
y = np.array([1.0, 3, 2, 5, 4, 6, 5, 8], dtype=float)
print(savgol_filter(y, 5, 2).round(2))from scipy import signal
t = np.linspace(0, 1, 200, endpoint=False)
b, a = signal.butter(3, 0.1)
filt = signal.filtfilt(b, a, np.sin(2 * np.pi * 3 * t))
print(filt[:4].round(3))from scipy.signal import detrend
y = np.arange(10, dtype=float) + np.sin(np.linspace(0, 6, 10))
plt.plot(y, label='raw')
plt.plot(detrend(y), label='detrend')
plt.legend()
plt.show()
print('ok')