How to pass another entire column as argument to pandas fillna()

后端 未结 6 2120
太阳男子
太阳男子 2020-11-22 07:01

I would like to fill missing values in one column with values from another column, using fillna method.

(I read that looping through each row would be

6条回答
  •  情话喂你
    2020-11-22 07:20

    You can provide this column to fillna (see docs), it will use those values on matching indexes to fill:

    In [17]: df['Cat1'].fillna(df['Cat2'])
    Out[17]:
    0    cat
    1    dog
    2    cat
    3    ant
    Name: Cat1, dtype: object
    

提交回复
热议问题