Quantcast
Channel: How do I fill NA values in multiple columns in pandas? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

How do I fill NA values in multiple columns in pandas?

$
0
0

I have a dataframe with 50 columns. I want to replace NAs with 0 in 10 columns.

What's the simplest, most readable way of doing this?

I was hoping for something like:

cols = ['a', 'b', 'c', 'd']df[cols].fillna(0, inplace=True)

But that gives me ValueError: Must pass DataFrame with boolean values only.

I found this answer, but it's rather hard to understand.


Viewing all articles
Browse latest Browse all 4

Trending Articles