column-wise fillna with Series/dict NotImplemented
See original GitHub issueAs 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:
- Created 10 years ago
- Comments:7 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Because nobody made the effort to implement it. But you are welcome to do so.
Faced the same issue. It is worth mentioning here, @hayd solution posted in StackOverflow
Thanks for the workaround Andy!