from scipy.signal import savgol_filter y_smooth = savgol_filter(y, 51, 3) # window size 51, polynomial order 3