close

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

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to pass another entire column as argument to pandas fillna() in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

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

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

    You can provide this column to fillna, it will use those values on matching indexes to fill: In [17]: df['Cat1'].fillna(df['Cat2']) Out[17]:

  2. pass another entire column as argument to pandas fillna()

    You can provide this column to fillna, it will use those values on matching indexes to fill: In [17]: df['Cat1'].fillna(df['Cat2']) Out[17]:

Method 1

You can provide this column to fillna, 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

Method 2

Just use the value parameter instead of method:

In [20]: df
Out[20]:
  Cat1      Cat2  Day
0  cat     mouse    1
1  dog  elephant    2
2  cat     giraf    3
3  NaN       ant    4

In [21]: df.Cat1 = df.Cat1.fillna(value=df.Cat2)

In [22]: df
Out[22]:
  Cat1      Cat2  Day
0  cat     mouse    1
1  dog  elephant    2
2  cat     giraf    3
3  ant       ant    4

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read