ts1 = [0, 1, np.nan, np.nan, np.nan, np.nan]
ts2 = [0, 2, np.nan, 3, np.nan, np.nan]
d = {'X': ts1, 'Y': ts2, 'Z': ts2}
df = pd.DataFrame(data=d)
print(df.head())
col = ['X', 'Y']
df[col] = df[col].ffill()
print(df.head())
forward fill specific columns in pandas dataframe