How to solve the Pandas issue related to Series.fillna()?

Viewed 10569

I just upgrade from Pandas 0.11 to 0.13.0rc1. The upgration caused one error related to Series.fillna().

>>> df
                   sales  net_pft
STK_ID RPT_Date                  
600809 20060331   5.8951   1.1241
       20060630   8.3031   1.5464
       20060930  11.9084   2.2990
       20061231      NaN   2.6060
       20070331   5.9129   1.3334

[5 rows x 2 columns]
>>> type(df['sales'])
<class 'pandas.core.series.Series'>
>>> df['sales'] = df['sales'].fillna(df['net_pft'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python27\lib\site-packages\pandas\core\generic.py", line 1912, in fillna
    obj.fillna(v, inplace=True)
AttributeError: 'numpy.float64' object has no attribute 'fillna'
>>> 

Why df['sales'] become 'numpy.float64' object when it is used in fillna() ? How to correctly do "fill the NaN of one column with the other column's value" ?

2 Answers
Related