wesm / pydata-book

Materials and IPython notebooks for "Python for Data Analysis" by Wes McKinney, published by O'Reilly Media

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ch05 adding obj3 + 4 - don't understand resulting value for "Utah"

inanoll2 opened this issue · comments

I have a question: when adding both obj 3 + 4, the result shows NaN for "Utah". However, in obj3, its value is 5000.

Why does it add values for Ohio, Oregon and Texas, but not for Utah? I would have expected it to show 5000.

Thanks for helping out.

Since 'Utah' is not present in obj4, is it treated as missing and so yields missing (null / NaN) in the result. You can get around this by using the add method:

>>> obj3.add(obj4, fill_value=0)
California         NaN
Ohio           70000.0
Oregon         32000.0
Texas         142000.0
Utah            5000.0
dtype: float64

This treats missing index values in obj3 or obj4 as 0