Getting last non na value across rows in a pandas dataframe

前端 未结 3 2073
北海茫月
北海茫月 2020-12-11 05:22

I have a dataframe of shape (40,500). Each row in the dataframe has some numerical values till some variable column number k, and all the entries after that are nan.

<
3条回答
  •  有刺的猬
    2020-12-11 05:48

    use agg('last')

    df.groupby(['status'] * df.shape[1], 1).agg('last')
    


    'last' within agg produces that last valid value within group. I passed a list of length equal to the number of columns. Each value of this list is 'status'. That means that I'm grouping by one group. The result is a dataframe with one column named 'status'

提交回复
热议问题