Fill blank cells from previous columns pandas python

后端 未结 2 615
鱼传尺愫
鱼传尺愫 2021-01-24 00:37

If I have a simple dataframe such as:

q_1     q_1_mark    q_2    q_2_mark
TRUE    a           1      c
FALSE   b           2   
TRUE    c           3   
<         


        
相关标签:
2条回答
  • 2021-01-24 01:01
    df.q_2_mark.fillna(df.q_1_mark, inplace=True)
    
    df
         q_1 q_1_mark  q_2 q_2_mark
    0   True        a    1        c
    1  False        b    2        b
    2   True        c    3        c
    
    0 讨论(0)
  • 2021-01-24 01:04

    Assuming your dataframe is df, Try:

    df.q_2_mark = df.q_2_mark.combine_first(df.q_1_mark) 
    
         q_1 q_1_mark  q_2 q_2_mark
    0   True        a    1        c
    1  False        b    2        b
    2   True        c    3        c
    
    0 讨论(0)
提交回复
热议问题