Reputation: 8072
I have this dataframe:
I want to create a ZIP column which will get the value of ZIP_y when ZIP_x is NaN and the value of ZIP_x when ZIP_x is not NaN.
I tried this code:
dm["ZIP"]=numpy.where(dm["ZIP_x"] is numpy.nan, dm["ZIP_y"],dm["ZIP_x"])
But that gave me this output:
As you can see, the ZIP column seems to be getting the values of ZIP_x in each of its cells.
Do you know how to achieve what I am after?
Upvotes: 1
Views: 134
Reputation: 394041
You want this:
dm["ZIP"]=numpy.where(dm["ZIP_x"].isnull(), dm["ZIP_y"],dm["ZIP_x"])
You can't use is
or ==
for that matter to compare NaN
s
Upvotes: 1