fillna ignoring axis=1 parameter
See original GitHub issueCode 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:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
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
closed by #42856