forward fill specific columns in pandas dataframe

前端 未结 4 701
一生所求
一生所求 2020-11-28 09:50

If I have a dataframe with multiple columns [\'x\', \'y\', \'z\'], how do I forward fill only one column \'x\'? Or a group of columns [\'x\',

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 10:26

    I used below code, Here for X and Y method can be different also instead of ffill().

     df1 = df.fillna({
            'X' : df['X'].ffill(),
            'Y' : df['Y'].ffill(),
        })
    

提交回复
热议问题