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.

fillna ignoring axis=1 parameter

See original GitHub issue

Code Sample, a copy-pastable example if possible

df = pd.DataFrame({'Col1':[np.nan]*5,
                   'Col2':[1]*5,
                   'Col3':[2,np.nan,2,2,2],
                   'Col4':[3,np.nan,3,np.nan,3],
                   'Col5':[4,np.nan,np.nan,np.nan,4],
                   'Col6':[np.nan]*5,
                   'Col7':[np.nan]*5,
                   'Col8':[np.nan]*5})

print(df)

   Col1  Col2  Col3  Col4  Col5  Col6  Col7  Col8
0   NaN     1   2.0   3.0   4.0   NaN   NaN   NaN
1   NaN     1   NaN   NaN   NaN   NaN   NaN   NaN
2   NaN     1   2.0   3.0   NaN   NaN   NaN   NaN
3   NaN     1   2.0   NaN   NaN   NaN   NaN   NaN
4   NaN     1   2.0   3.0   4.0   NaN   NaN   NaN

df.fillna(0,limit=2,axis=1)


   Col1  Col2  Col3  Col4  Col5  Col6  Col7  Col8
0   0.0     1   2.0   3.0   4.0   0.0   0.0   0.0
1   0.0     1   0.0   0.0   0.0   0.0   0.0   0.0
2   NaN     1   2.0   3.0   0.0   NaN   NaN   NaN
3   NaN     1   2.0   0.0   NaN   NaN   NaN   NaN
4   NaN     1   2.0   3.0   4.0   NaN   NaN   NaN

Problem description

df.fillna is ignoring axis=1 parameter

Expected Output

df.T.fillna(0,limit=2,axis=1).T

   Col1  Col2  Col3  Col4  Col5  Col6  Col7  Col8
0   0.0   1.0   2.0   3.0   4.0   0.0   NaN   NaN
1   0.0   1.0   0.0   NaN   NaN   NaN   NaN   NaN
2   0.0   1.0   2.0   3.0   0.0   NaN   NaN   NaN
3   0.0   1.0   2.0   0.0   NaN   NaN   NaN   NaN
4   0.0   1.0   2.0   3.0   4.0   0.0   NaN   NaN

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None python: 3.5.2.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 26 Stepping 5, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None

pandas: 0.20.3 pytest: 2.9.2 pip: 9.0.1 setuptools: 27.2.0 Cython: 0.25.2 numpy: 1.13.1 scipy: 0.19.0 xarray: 0.9.6 IPython: 5.1.0 sphinx: 1.4.6 patsy: 0.4.1 dateutil: 2.6.1 pytz: 2017.2 blosc: None bottleneck: 1.1.0 tables: 3.2.2 numexpr: 2.6.2 feather: None matplotlib: 2.0.0 openpyxl: 2.3.2 xlrd: 1.0.0 xlwt: 1.1.2 xlsxwriter: 0.9.3 lxml: 3.6.4 bs4: 4.5.1 html5lib: 0.999999999 sqlalchemy: 1.0.13 pymysql: None psycopg2: None jinja2: 2.8 s3fs: None pandas_gbq: None pandas_datareader: 0.2.1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jorviscommented, Sep 11, 2019

Is this possibly still an issue? I’m able to reproduce it, but with 0.24.2 which should long-since have the fix:

https://imgur.com/a/3ZrXqSv

0reactions
jbrockmendelcommented, Jan 5, 2022

closed by #42856

Read more comments on GitHub >

github_iconTop Results From Across the Web

fillna() method's behavior in Pandas -- does not obey to ...
I tried the inplace argument and still is not working. Moreover, the replace method returns an error when called with axis=1. Therefore, it...
Read more >
pandas: Replace missing values (NaN) with fillna() - nkmk note
You can replace the missing value (NaN) in pandas.DataFrame and Series with any value using the fillna() method.pandas.
Read more >
How to work with missing data using Pandas? - Numpy Ninja
Method: The method parameter represents the technique that needs to be used for filling the Nan's in the dataframe. Axis: This argument ......
Read more >
Working with missing data — pandas 1.5.2 documentation
Cumulative methods like cumsum() and cumprod() ignore NA values by default, ... fillna() can “fill in” NA values with non-NA data in a...
Read more >
Using Panda's “transform” and “apply” to deal with missing ...
Recap of Pandas' fillna · method='ffill': Ffill or forward-fill propagates the last observed non-null value forward until another non-null value ...
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