0

I have a dataframe called firstpart.

I'm trying to update the values in one column (Key), but only for rows in which another column (Zone) has no data.

I'm using this code, which doesn't work:

firstpart.ix[firstpart.Zone ==np.nan,"Key"] = "newvalue"

Neither does this:

firstpart.ix[firstpart.Zone =="","Key"] = "newvalue"

Using this syntax I'm able to update values in rows for which Zone has another value, but for some reason not if I try to select the rows in which it is blank.

What am I doing wrong?

1 Answer 1

1
firstpart.ix[firstpart.Zone.isnull()] = "newvalue"

You can't equate NaN to anything.

In [1]: NaN == NaN
Out[1]: False

You need special methods for that, and this is what .isnull() is about.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.