Skip to content

fillna ignoring axis=1 parameter #17399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scottboston opened this issue Aug 31, 2017 · 5 comments
Closed

fillna ignoring axis=1 parameter #17399

scottboston opened this issue Aug 31, 2017 · 5 comments
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Comments

@scottboston
Copy link

scottboston commented Aug 31, 2017

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

@TomAugspurger TomAugspurger added Bug Difficulty Intermediate Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate labels Aug 31, 2017
@TomAugspurger
Copy link
Contributor

This seems to be buggy specifically for filling by a value (not a method like ffill).

@scottboston do you have a chance to figure out where the bug is and submit a PR?

@scottboston
Copy link
Author

@TomAugspurger I will have a look at it.

pratapvardhan added a commit to pratapvardhan/pandas that referenced this issue Sep 1, 2017
pratapvardhan added a commit to pratapvardhan/pandas that referenced this issue Sep 1, 2017
@jreback jreback added this to the Next Major Release milestone Sep 23, 2017
@jorvis
Copy link

jorvis commented 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

@jreback
Copy link
Contributor

jreback commented Sep 11, 2019

the referenced PR was closed as stale and not merged; this issue is still open

@jbrockmendel
Copy link
Member

closed by #42856

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
5 participants