import pandas as pd
import numpy as np
t1 = [0, 1, np.nan, np.nan, np.nan, np.nan]
t2 = [0, 2, np.nan, 3, np.nan, np.nan]
d = {'X': t1, 'Y': t2, 'Z': t2}
df = pd.DataFrame(data=d)
print(df)
col =['X','Y'] # 需要填充的列
df[col] = df[col].ffill() # 设定填充方式
print(df)
填充前
填充后