question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

column-wise fillna with Series/dict NotImplemented

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Feb 9, 2018

curious why this issue is still open in 2018.

Because nobody made the effort to implement it. But you are welcome to do so.

0reactions
malbahranicommented, Apr 18, 2018

Faced the same issue. It is worth mentioning here, @hayd solution posted in StackOverflow

Thanks for the workaround Andy!

Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas fillna Currently only can fill with dict/Series column by ...
I tried to fillna to replace NaN with a string not existed . df.fillna(value={'A': 'not existed'}, axis=1, inplace= ...
Read more >
pandas.Series.fillna — pandas 1.5.2 documentation
Fill NA /NaN values using the specified method. ... of values specifying which value to use for each index (for a Series) or...
Read more >
Source code for pyspark.pandas.frame - Apache Spark
It has the row axis labels and column axis labels as the only members. ... 0: raise NotImplementedError("fillna currently only works for axis=0...
Read more >
pandas.core.frame — Lux 0.1.2 documentation
Raises NotImplementedError if a datetime column has timezone information. ... Optional["DataFrame"]: return super().fillna( value=value, method=method, ...
Read more >
[Solved]-Can fillna take in a function or just the given methods?
Series(dict (W=-9, X=-10, Y=-11, Z=-12)) df.fillna(filler) W X Y Z A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found