Skip to content
Advertisement

Updating column value based on nan value of other column

I have this simple function with 2 columns. What I’m trying to do is to check what group has a number of nan and change it to a new desired value. Here’s a code snippet:

JavaScript

Before: This is how the data looks like, you can assume numbers are sorted.

JavaScript

In my example I know where nan and since it was at position 4, I was able to use loc to change it to a 100, like this:

JavaScript

What if I don’t know where the nan is? How can I know which group to update? All that comes to my mind is nested for loop which I would rather avoid… Any suggestions here?

Advertisement

Answer

You could replace

JavaScript

with

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement