Categories
Python Answers

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

Spread the love

To pass another entire column as argument to Python Pandas fillna(), we call fillna with the column directly.

For instance, we write

df['Cat1'].fillna(df['Cat2'])

to call fillna with df['Cat2'] to pass the column as the argument to replace NaN values with the values from the Cat2 column.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *