Use low-pass filter. Take a look here: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.butter.html
or even better here: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.filtfilt.html
filtfilt
function applies filter twice, from the beginning, and from the end, so that delay that occurs due to filtering is removed (two opposite delays eliminate each other)
you will need to adjust filter parameters, most important - cut-off frequency
(set order of the filter to 5-10), try different values around 0.05-0.2.
sig = [0, 1, 0, 1, 0, 1, 0, 1, 0] # your signal
b, a = signal.butter(8, 0.1)
filtered_signal = signal.filtfilt(b, a, sig, method="gust")