Skip to content

column-wise fillna with Series/dict NotImplemented #4514

Open
@hayd

Description

@hayd

As per discussion on this SO question is NotImplementedError.

Solution/workaround is to transpose do transpose? This is used elsewhere in DataFrame.fillna method. just raise if inplace?

cc @cpcloud

In [9]: df = pd.DataFrame([[np.nan, np.nan], [np.nan, 4], [5, 6]], columns=list('AB'))

In [10]: df
Out[10]:
    A   B
0 NaN NaN
1 NaN   4
2   5   6

In [11]: df.mean(0)
Out[11]:
A    5
B    5
dtype: float64

In [12]: df.fillna(df.mean())
Out[12]:
   A  B
0  5  5
1  5  4
2  5  6

In [13]: df.mean(1)
Out[13]:
0    NaN
1    4.0
2    5.5
dtype: float64

In [14]: df.fillna(df.mean(1), axis=1)
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-14-aecc493431e2> in <module>()
----> 1 df.fillna(df.mean(1), axis=1)

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/frame.pyc in fillna(self, value, method, axis, inplace, limit, downcast)
   3452             if isinstance(value, (dict, Series)):
   3453                 if axis == 1:
-> 3454                     raise NotImplementedError('Currently only can fill '
   3455                                               'with dict/Series column '
   3456                                               'by column')

NotImplementedError: Currently only can fill with dict/Series column by column

Metadata

Metadata

Labels

EnhancementMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions